update fin_com_compare a
   set a.center_code = (select b.item_code
                          from fin_com_siitem b
                         where b.name = a.center_name
                           and a.center_code = 'Test'
                           and a.center_name is not null)----上面的sql执行的时候报错 ora-01407 无法更新center_code为Null
  where exists (select 1 from fin_com_siitem b where b.name = a.center_name)
    and a.center_code = 'Test'
    and a.center_name is not null--加上where条件后 报错 ora-01427 单个子查询返回多个行  什么原因啊。实际上我的意思就是如果  b表的name与a表的center_name相同的话 将b表的item_code更新到a表的center_code

解决方案 »

  1.   

    select b.item_code
      from fin_com_siitem b
      where b.name = a.center_name
      and a.center_code = 'Test'
      and a.center_name is not null这个返回值唯一么?
      

  2.   

    如果一个A表的center_name对应了多个B表的name,那么就会发现错误了。
      

  3.   

    b.item_code是重复的。不这样update不允许重复吗。
      

  4.   

    这样执行的sql的执行过程是什么那。
      

  5.   

    b表里面的 name  item_code 是唯一对应的不?
    应该是  1   a
           2   b
           3   c 这样的就可以
    如果是有   1   a  
             1   b 
    或者
            1   a
           2   a
    就不行了。
    update fin_com_compare a
      set a.center_code = (select b.item_code
      from (select  distinct name,item_code from fin_com_siitem ) b 
      where exists (select 1 from b where b.name = a.center_name)
      and a.center_code = 'Test'
      and a.center_name is not null
    )
      

  6.   


    merge into fin_com_compare a
         using fin_com_siitem b
            on(    b.name = a.center_name)
       when matched then
         update set a.center_code = b.item_code
          where a.center_code = 'Test'
            and a.center_name is not null;
      

  7.   


    b表里面的是唯一的的  例如 1 a ,2 b .....
      

  8.   

    问题找到了,谢谢啊。
    原因就是name有重复的。