此SQL在MS SQL Server上正常工作但产生错误“ORA-00907:缺少右括号”。
SQL:
UPDATE DELIVERY
SET VISIBLE = 0
WHERE DELIVERY.ID
IN
(
SELECT DELIVERY.ID FROM delivery WHERE DELIVERY.VISIBLE = 1
EXCEPT
SELECT DELIVERY.ID FROM delivery LEFT JOIN inventory ON INVENTORY.DELIVERYID = DELIVERY.ID
WHERE ((DELIVERY.VISIBLE = 1) AND (INVENTORY.VISIBLE = 1)) AND (INVENTORY.INVENTORYSTATE = 3)
);
有没有办法让这个在Oracle上运行,或者是一个使用IN和SELECT语句的UPDATE在概念上是错误的?
答案 0 :(得分:1)
在Oracle中,IN也可以工作,只需在Oracle中将EXCEPT更改为MINUS即可 http://www.techonthenet.com/sql/update.php
http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_10007.htm
http://docs.oracle.com/cd/E17952_01/refman-5.0-en/exists-and-not-exists-subqueries.html
此示例示例
UPDATE DELIVERY
SET VISIBLE = 0
WHERE DELIVERY.ID
IN
(
(SELECT DELIVERY.ID FROM delivery WHERE DELIVERY.VISIBLE = 1)
MINUS
(SELECT DELIVERY.ID
FROM delivery LEFT JOIN inventory ON INVENTORY.DELIVERYID = DELIVERY.ID
WHERE (((DELIVERY.VISIBLE = 1) AND (INVENTORY.VISIBLE = 1))
AND (INVENTORY.INVENTORYSTATE = 3)))
);
答案 1 :(得分:0)
我认为您可以修改此查询,以便它在SQL Server 和 Oracle中都有效:
UPDATE delivery d
SET d.visible = 0
WHERE d.visible = 1
AND NOT EXISTS ( SELECT 1 FROM inventory i
WHERE i.deliveryid = d.id
AND i.visible = 1
AND i.inventorystate = 3 )
这会在DELIVERY
= 1的任何地方更新visible
设置visible
= 0,但INVENTORY
中visible
= 1和{{{{}}中没有相应的记录1}} = 3。