解决方案 »

  1.   

    加个nvl或者decode函数就行了
    如:update ta set a=(select nvl(tb.a,ta.a) from tb);
      

  2.   

    加个nvl或者decode函数就行了
    如:update ta set a=(select nvl(tb.a,ta.a) from tb);这个是不是只能用在 updata table_a set a =……, b =……,c=……,这种方式上,因为 更新有关联条件限制,所以想以这种 set (a,  b,  c ,d,  e  ,f  ,g) 
    = ( select a,  b,  c ,d,  e  ,f  ,g from table_b ) 多个字段一起更新的方式, 这种方式的话,改怎么办?
      

  3.   

    可以用merge into试试,如果不行就只能一个一个来update
    MERGE INTO ta p
    USING tb np
    ON (p.c1 = np.c1 and p.c2 = np.c2) --连接条件
    WHEN MATCHED THEN
      UPDATE
         SET p.c3 = nvl(np.c3, p.c3), p.c4 = nvl(np.c4, p.c4) --注意此处update的字段不能作为连接字段(不能更新c1,c2字段)
       WHERE p.c4 = 'sasfdsa' --可以叫条件过滤
      

  4.   

    楼上可能想多了,正常table_a中的 table_b中没有的记录会被置空,只要限定where条件不更新那部分就可以了
    update table_a
    set (a,  b,  c ,d,  e  ,f  ,g) 
    = ( select a,  b,  c ,d,  e  ,f  ,g from table_b where id=table_a.id)
    where exists (select 1 from table_b where id=table_a.id)
      

  5.   

    update table_a A
    set (a,  b,  c ,d,  e  ,f  ,g) 
    = ( select NVL(A.a,B.a),NVL(A.b,B.b),…… from table_b B where id=A.id )
    where exists (select 1 from table_b B where id=A.id)