ストアド プロシージャ内に次のスニペットがあります。
(注: これは元のスニペットではありませんが、テーブルと列の名前がより一般的なものに置き換えられていることを除いて、元のスニペットとまったく同じです。理解を深め、クライアント コードの配布を防ぎます。)
UPDATE table_Orders c SET order_type =
(
SELECT 'PE' FROM
table_Orders A,
table_Orders b,
(SELECT DISTINCT order_id, cust_id, order_date FROM table_Orders WHERE shipment_type = 'T' AND order_availability = 'P' AND order_amt > 500
AND cust_category = 'PREMIUM' ) d
WHERE
A.order_id = d.order_id AND A.order_date = d.order_date AND A.cust_id= d.cust_id
AND A.order_id = b.order_id AND A.order_date = b.order_date AND A.cust_id= b.cust_id
AND A.shipment_type = b.shipment_type AND A.order_availability = b.order_availability AND A.product_id <> b.product_id
AND ((A.order_amt > 500 AND b.shipment_amt > 50) OR (A.shipment_amt > 50 AND b.order_amt > 500))
AND A.order_id = c.order_id AND A.order_date = c.order_date AND A.cust_id = c.cust_id
AND A.shipment_type = c.shipment_type AND A.order_availability = c.order_availability AND A.product_id = c.product_id
);
COMMIT;
さて、私の問題はORA-01427 single-row subquery returns more than one row
、手順の実行中にエラーが発生することです。以下のように句を使用してステートメントの最後にサブクエリを配置しようとしましたIN
が、それでも機能しませんでした。
UPDATE table_Orders c SET order_type =
(
SELECT 'PE' FROM
table_Orders A,
table_Orders b
WHERE
A.order_id = d.order_id AND A.order_date = d.order_date AND A.cust_id= d.cust_id
AND A.order_id = b.order_id AND A.order_date = b.order_date AND A.cust_id= b.cust_id
AND A.shipment_type = b.shipment_type AND A.order_availability = b.order_availability AND A.product_id <> b.product_id
AND ((A.order_amt > 500 AND b.shipment_amt > 50) OR (A.shipment_amt > 50 AND b.order_amt > 500))
AND A.order_id = c.order_id AND A.order_date = c.order_date AND A.cust_id = c.cust_id
AND A.shipment_type = c.shipment_type AND A.order_availability = c.order_availability AND A.product_id = c.product_id
AND (A.order_id, A.cust_id, A.order_date) IN
(SELECT DISTINCT order_id, cust_id, order_date FROM table_Orders
WHERE shipment_type = 'T' AND order_availability = 'P' AND order_amt > 500 AND cust_category = 'PREMIUM')
);
COMMIT;
誰かが私を正しい方向に案内してくれませんか?
JOIN を使用したコード --> これにより、「JOIN」ステートメントの直前の c.product_Id に右括弧がありません
UPDATE table_Orders c SET order_type =
(
SELECT 'PE' FROM
table_Orders A,
table_Orders b
WHERE
A.order_id = d.order_id AND A.order_date = d.order_date AND A.cust_id= d.cust_id
AND A.order_id = b.order_id AND A.order_date = b.order_date AND A.cust_id= b.cust_id
AND A.shipment_type = b.shipment_type AND A.order_availability = b.order_availability AND A.product_id <> b.product_id
AND ((A.order_amt > 500 AND b.shipment_amt > 50) OR (A.shipment_amt > 50 AND b.order_amt > 500))
AND A.order_id = c.order_id AND A.order_date = c.order_date AND A.cust_id = c.cust_id
AND A.shipment_type = c.shipment_type AND A.order_availability = c.order_availability AND A.product_id = c.product_id
JOIN
SELECT DISTINCT order_id, cust_id, order_date FROM table_Orders
WHERE shipment_type = 'T' AND order_availability = 'P' AND order_amt > 500 AND cust_category = 'PREMIUM' d
ON A.order_id = d.order_id AND A.order_date = d.order_date AND A.cust_id= d.cust_id
COMMIT;