两个表:
表A
name price
aaa 10.1
bbb 11.1
ccc 12.1
ddd 13.1
表B
name price
aaa 100
bbb 200
ccc 300现在要求:把B表中跟A表name相同的字段的price更新到A表,即更新aaa bbb ccc的price 如何写语句 谢谢
表A
name price
aaa 10.1
bbb 11.1
ccc 12.1
ddd 13.1
表B
name price
aaa 100
bbb 200
ccc 300现在要求:把B表中跟A表name相同的字段的price更新到A表,即更新aaa bbb ccc的price 如何写语句 谢谢
UPDATE tableName1 set price=(select price from tableName2 where tableName2.name=tableName1.name)
--1
merge into A
using B
on(A.name=B.name)
when matched then
update set A.price = B.price;--2
update A
set A.price = (select B.price from A,B where A.name = B.name)
where exists(select 1 from A,B where A.name = B.name);--3
update(
select A.price p1,B.price p2
from A,B
where A.name = B.name)
set p1=p2;
第三种方式应该用的比较少,而且如果没有建立PK或者唯一索引,果断报ORA-01779错误。