A  表   TBR  填报人  dept 所部门属
B  表   ACCOUNT 账号    dept 所部门属
现在A表  部门字段出现空值    属于垃圾数据,要填写上部门
A表和B表  通过 TBR = ACCOUNT 关联   目的就是找出A表的dept为空的数据   根据关联从B表找出部门填写到A表上 我不会写 请高手赐教 

解决方案 »

  1.   

    update A set dept=(select max(dept) from B where A.TBR = B.ACCOUNT) where A.dept is null
      

  2.   


    update A set A.dept=(select B.dept from B where A.TBR=B.ACCOUNT) where A.dept is null;
      

  3.   

    你的B表的数据是什么样的,同一个账号会对应不同的部门吗?
    没有的话
    UPDATE a
       SET a.dept = (SELECT b.dept
                       FROM b
                      WHERE a.tbr = b.ACCOUNT
        AND ROWNUM=1)
     WHERE a.dept IS NULL;同一个账号会对应不同的部门的话,就看你怎么取部门了,如果也是随意的话那和上面的那个一样
      

  4.   


    update tabA a
       set a.dept = (select b.dept
                       from tabB b
                      where a.TBR = b.ACCOUNT
                        and a.dept is null)
     where exists (select 1
              from tabA a, tabB b
             where a.TBR = b.ACCOUNT
               and a.dept is null);
    commit;
      

  5.   

    我理解着你有可能 是需要这个 
    select A.TBR , NVL(A.DEPT,B.DEPT) FROM A,B 
      WHERE A.TBR = B.ACCOUNT(+) ;
      

  6.   

    update tabA a
       set a.dept = (select b.dept
                       from tabB b
                      where a.TBR = b.ACCOUNT
                        and a.dept is null)
     where exists (select 1
              from tabA a, tabB b
             where a.TBR = b.ACCOUNT
               and a.dept is null);
    commit;
      

  7.   

    update table_a a set a.dept = (select b.deptno from table_b b where a.tbr = b.account) where a.dept is null;
      

  8.   

    用一个嵌套即可:
    update A set A.dept=(select B.dept from B where A.TBR=B.ACCOUNT) where A.dept is null;
      

  9.   

    update A set dept=(select max(dept) from B where A.TBR = B.ACCOUNT) where A.dept is null
      

  10.   

    update tabA a
       set a.dept = (select b.dept
                       from tabB b
                      where a.TBR = b.ACCOUNT
                        and a.dept is null)
     where exists (select 1
              from tabA a, tabB b
             where a.TBR = b.ACCOUNT
               and a.dept is null);
    commit;
      

  11.   

    update a set a.dept=
    (select b.dept from b where a.TBR=b.account and rownum=1)
    where a.dept is null;
      

  12.   

    update tabA a
      set a.dept = (select b.dept
      from tabB b
      where a.TBR = b.ACCOUNT
      and a.dept is null)
     where exists (select 1
      from tabA a, tabB b
      where a.TBR = b.ACCOUNT
      and a.dept is null);
    commit;
      

  13.   

    update tabA a
       set a.dept = (select b.dept
                       from tabB b
                      where a.TBR = b.ACCOUNT
                        and a.dept is null)
     where exists (select 1
                     from tabA a, tabB b
                    where a.TBR = b.ACCOUNT
                      and a.dept is null);
    commit;
      

  14.   

    支持3楼 
               update A 
               set A.dept=(select B.dept
                           from B 
                           where A.TBR=B.ACCOUNT)
               where A.dept is null