如果我有两个表:Table A 和Table B
Table A(colA1,colA2,colA3)
Table B(colB1,colB2,colB3)如果要将B表的记录插入到A表中,可用下面的SQL:
insert A(colA1,colA2,colA3)
      select colB1,colB2,colB3 from B;若我要把Table B中的colB2,colB3 更新到Table A中的colA2,colA3,其中A.colA1 = B.colB1
不可用下面的sql语句
update A a set (colA2,colA3)
=(select colB2,colB3 from B where colB1 = a.colA1);
那应该怎么写才能更新A表中的若干记录呢?

解决方案 »

  1.   

     merge into a
      using b
      on (a.cola1=b.colb1)        --关联条件
      when matched then       --匹配关联条件,作更新处理
      update set
      a.cola2=b.colb2,
      a.cola3=b.colb3
      

  2.   

    select colB2,colB3 from B where colB1 = a.colA1这个子查询得到的是多行数据,与更新操作是不匹配的!
      

  3.   

    merge into a
      using b
      on (a.cola1=b.colb1) --关联条件
      when matched then --匹配关联条件,作更新处理
      update set
      a.cola2=b.colb2,
      a.cola3=b.colb3