尝试进行简单的更新,但SQL错误:ORA-01779:无法修改映射到非键保留表的列

问题描述 投票:0回答: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';

谢谢您的帮助!

sql oracle11g sql-update
1个回答
0
投票

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

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';

0
投票

您可以使用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中根本没有任何行,但该逻辑将不符合您当前的查询,您可能还需要一个条件。

© www.soinside.com 2019 - 2024. All rights reserved.