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
...本人初学,请求写出详细代码.

解决方案 »

  1.   

    不考虑a中的数据有一部分在b中间不存在的情况:
    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)
      

  2.   

    update tablea
    set c=(select d from tableb
    where tableb.a=tablea.a)
    where exists(select 1 from tableb
    where tableb.a=tablea.a);
      

  3.   


    update tableA
       set c = (select d from tableB where tableA.a = tableB.a)
     where exists (select 1 from tableB2 where tableA.a = tableB.a);
      

  4.   

    --因为你的2个表都有主键,因此可以写:
    update
    (
      select a.c, b.d
        from a, b
       where a.a = b.a
    )
    set c = d;
      

  5.   


    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;
      

  6.   

    楼上少个分号create or replace procedure pro_test 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 ;