update A a set a.bbb= (select b.ddd from B b where a.aaa=b.ccc);
update A a set a.bbb= (select b.ddd from B b where a.aaa=b.ccc);
这样不好,A表里有,B表没有的字段,都更新为空了,也破环了A不符合条件的数据
update b a set b.ddd=(select a.bbb from a where a.aaa=b.ccc);
merge into b using a on (a.aaa = b.ccc) when matched then update set b.ddd = a.bbb;
update B set B.ddd=( select A.bbb from A where A.aaa=B.ccc) where exists( select 1 from A where A.aaa=B.ccc);
update B t set t.ddd = (select s.bbb from A s where t.ccc = s.aaa) where exists (select 1 from A s where t.ccc = s.aaa);
update A a set a.bbb= (select b.ddd from B b where a.aaa=b.ccc);
两张表A(aaa,bbb),B(ccc,ddd) aaa,ccc可以关联,把bbb字段更新到ddd字段里 求一条Oracle 语句update b set ddd = (select bbb from a where a.aaa = b.ccc and rownum <=1) where exists (select 1 from a where a.aaa = b.ccc);
(select b.ddd from B b where a.aaa=b.ccc);
(select b.ddd from B b where a.aaa=b.ccc);
merge into b
using a
on (a.aaa = b.ccc)
when matched then
update set b.ddd = a.bbb;
update B set B.ddd=(
select A.bbb from A where A.aaa=B.ccc)
where exists(
select 1 from A where A.aaa=B.ccc);
set t.ddd = (select s.bbb from A s where t.ccc = s.aaa)
where exists (select 1 from A s where t.ccc = s.aaa);
(select b.ddd from B b where a.aaa=b.ccc);
求一条Oracle 语句update b
set ddd = (select bbb from a where a.aaa = b.ccc and rownum <=1)
where exists
(select 1 from a where a.aaa = b.ccc);
ORA-30926:无法在源表中获得一组稳定的行
在更新数据出现 这个错误
六楼的是对的。ORACLE的UPDATE语句一定要加EXISTS子句,否则会把B表的所有记录都UPDATE。
aaa bbb
1 2222
1 3333
那,用bbb更新B表,到底用2222還是3333呢?請把表結構列出來看看