Oracle
選擇返回正確結果時更新不起作用
我正在嘗試執行以下查詢:
UPDATE( SELECT Ord.Completed FROM Product P INNER JOIN Order1 Ord ON Ord.OrderID = P.OrderID WHERE EXISTS( SELECT * FROM Delivery D WHERE Delivery.Delivered = 0 AND P.ProductID = Delivery.DeliveryID ) ) SET Completed= 'NO';
如果我只執行 SELECT 部分,沒有 UPDATE 它返回正確的結果。當我嘗試執行 UPDATE 查詢時,我得到
"ORA-00933: SQL command not properly ended 00933. 00000 - "SQL command not properly ended" *Cause: *Action: Error at Line: 2 Column: 250"
有任何想法嗎?
請試試這個:
UPDATE( SELECT Ord.OrderID, Ord.Completed FROM Order1 Ord WHERE EXISTS( SELECT * FROM Product P INNER JOIN Delivery D ON Delivery.Delivered = 0 AND P.ProductID = Delivery.DeliveryID WHERE Ord.OrderID = P.OrderID ) ) SET Completed = 'NO' ;
或沒有派生表:
UPDATE Order1 Ord SET Completed = 'NO' WHERE EXISTS( SELECT * FROM Product P INNER JOIN Delivery D ON Delivery.Delivered = 0 AND P.ProductID = Delivery.DeliveryID WHERE Ord.OrderID = P.OrderID );