1

我正在尝试使用两个表进行简单更新,但出现此错误: SQL 错误:ORA-01779:无法修改映射到非键保留表的列 我已经找到了很多解决方案,我已经试过了,但还是不行……你能帮我解决吗?

update (SELECT t1.STATUS from table1 t1 inner join table2 t2 on(t1.ID = t2.ID) 
where t1.STATUS like 'COMPLETE' and t2.PARTY is null) vp set vp.STATUS= 'NEW';

谢谢您的帮助 !

4

2 回答 2

1

您可以使用update但与相关的子查询:

update table1 t1
    set status = 'NEW'
    where t1.status = 'COMPLETE' and
          exists (select 1
                  from table2 t2 
                  where t1.ID = t2.ID and t2.party is null
                 );

我怀疑如果根本没有行table2但该逻辑不符合您当前的查询,您可能还需要一个条件。

于 2020-03-06T14:59:30.807 回答
0

您可以通过使用合并语句来做到这一点:

MERGE INTO table1 tgt
  USING (SELECT id
         FROM   table2
         WHERE  party IS NULL) src
    ON (tgt.id = src.id) -- ensure this join condition means there's only one source row per target row
WHEN MATCHED THEN
  UPDATE tgt.status = 'NEW'
  WHERE  tgt.status = 'COMPLETE';
于 2020-03-06T14:56:58.737 回答