A表:
a b c
1 ww 123
2 sa 45
5 gg 78
...
B表:
a b d
1 af 56
2 ff 33
6 ee 47
...
AB两表的主键均是字段a
要求将B表中字段d的值更新到A表字段c的值,条件是AB两表的主键值相同.
比如上面A表可以更新成:
a b c
1 ww 56
2 sa 33
5 gg 78
...本人初学,请求写出详细代码.
a b c
1 ww 123
2 sa 45
5 gg 78
...
B表:
a b d
1 af 56
2 ff 33
6 ee 47
...
AB两表的主键均是字段a
要求将B表中字段d的值更新到A表字段c的值,条件是AB两表的主键值相同.
比如上面A表可以更新成:
a b c
1 ww 56
2 sa 33
5 gg 78
...本人初学,请求写出详细代码.
update a set b,c=(select b,d from b where b.a=a.a)考虑a中的数据有一部分在b中间不存在的情况:
update a set b,c=(select b,d from b where b.a=a.a)
where exists (select 1 from b where b.a=a.a)
set c=(select d from tableb
where tableb.a=tablea.a)
where exists(select 1 from tableb
where tableb.a=tablea.a);
update tableA
set c = (select d from tableB where tableA.a = tableB.a)
where exists (select 1 from tableB2 where tableA.a = tableB.a);
update
(
select a.c, b.d
from a, b
where a.a = b.a
)
set c = d;
create or replace procedure TEST_20081021 is
begin
update A set c=(select d from b where b.a=a.a)
where exists (select 1 from b where b.a=a.a)
end TEST_20081021;
begin
update A
set c = (select d from b where b.a = a.a)
where exists (select 1 from b where b.a = a.a);
end ;