有人可以验证内部联接是否对PL SQL中的UPDATE语句有效? e.g。
Update table t
set t.value='value'
from tableb b inner join
on t.id=b.id
inner join tablec c on
c.id=b.id
inner join tabled d on
d.id=c.id
where d.key=1
答案 0 :(得分:15)
此synthax在Oracle SQL中不起作用。
在Oracle you can update a join if the tables are "key-preserved"中,即:
UPDATE (SELECT a.val_a, b.val_b
FROM table a
JOIN table b ON a.b_pk = b.b_pk)
SET val_a = val_b
假设b_pk
是b
的主键,此处的连接是可更新的,因为对于A的每一行,最多最多来自B的一行,因此更新是确定性的。
在您的情况下,由于更新后的值不依赖于另一个表,您可以使用带有EXIST条件的简单更新,如下所示:
UPDATE mytable t
SET t.VALUE = 'value'
WHERE EXISTS
(SELECT NULL
FROM tableb b
INNER JOIN tablec c ON c.id = b.id
INNER JOIN tabled d ON d.id = c.id
WHERE t.id = b.id
AND d.key = 1)
答案 1 :(得分:1)
update t T
set T.value = 'value'
where T.id in (select id from t T2, b B, c C, d D
where T2.id=B.id and B.id=C.id and C.id=D.id and D.key=1)
-- t is the table name, T is the variable used to reffer to this table