表A
字段m1,m2
表B 
字段n1
要循环A表
执行update B set n1 = m2 where n1 = m1

解决方案 »

  1.   


    --可使用merge into来批量更新
    merge into tb_b b
    using tb_a a 
    on( a.m1 = b.n1 )
    when matched then
         update
         set b.n1 = a.m2
    when not matched then--如果没有此要求,可设为null
      -- insert (b.n1)
      --values (a.m2);
      --or null
      

  2.   

    这个还是有问题 无法更新ON字句中引用的列"b"."n1"
      

  3.   


    --直接更新不可以吗?
    update tb_b b
    set n1=(
        select m2 from tb_a a
        where a.m1=b.n1)
    where exists(
          select 1 from tb_a c
          where b.m1=c.n1)
      

  4.   

    merge into 不能更新关联列。update b set b.n1 = (select a.m2 from a where a.m1 = b.n1);
      

  5.   


    这个update语句写的有问题,楼上的是对的。