create table aa(a number, b number, c number)
create table bb(a number, b number, c number)aa
a       b       c
1 0 0
2 0 0
3 0 0
bb
a        b      c
1 1 1
2 2 2
3 3 3
4 4 4
现在要根据aa中的a字段和bb中的a字段来更新aa的数据,得到
a        b      c
1 1 1
2 2 2
3 3 3我想到了这种方法,但是不好,重复了
update aa ta set ta.b = (select b from bb where ta.a = a),ta.c = (select c from bb where ta.a = a)大家帮忙看看

解决方案 »

  1.   

    update aa ta set (ta.b,ta.c) = (select b,c from bb where ta.a = a);
      

  2.   


    update aa
    set (a,b,c)
    =(select a,b,c from bb where bb.a=aa.a)
    where exists (select a,b,c from bb where bb.a=aa.a)
      

  3.   

    update aa ta
       set (ta.b, ta.c) = (select b, c from bb where ta.a = a)
     where exists (select 1 from bb where ta.a = a);
      

  4.   

    让得加上where exists...,不然你这种数据的更新会有问题,自己试一下就知道.
      

  5.   


    update
      select aa.b b1, aa.c c1, bb.b b2, bb.c c2
      from aa, bb
      where aa.a = bb.a
    set
    (  
      b1 = b2, 
      c1 = c2
    )
    ;
      

  6.   

    oracle和sql server的语法都不一样啊,郁闷。sqlserver里这样的可以。oracle不熟悉
     update aa
     set
     aa.b = bb.b,
     aa.c = bb.c
     from bb
     where aa.a = bb.a