select t1.awb_no, t1.from_city as EI, t2.data_no as AC
  from ehu_awb t1, plmdebtm t2
 where t1.from_city <> t2.data_no
   and t1.dep = 'EI'
   and t1.cmp = 'BX'
   and t1.awb_no = t2.AWB_NO就是查询T1中的from_city和T2中的data_no字段,如果相同的提单号awb_no,却为进口EI,则把T1的from_city UPDATE到T2的data_no,如何写update语法。
之前我写的不对。update plmdebtm
       set plmdebtm.data_no =
           (select ehu_awb.from_city
              from ehu_awb
             where ehu_awb.awb_no = plmdebtm.awb_no
               and ehu_awb.from_city <> plmdebtm.data_no
               and ehu_awb.dep = 'EI')上面的会把表plmdebtm的所有的行都更新了。

解决方案 »

  1.   

    update plmdebtm
           set plmdebtm.data_no =
               (select ehu_awb.from_city
                  from ehu_awb
                 where ehu_awb.awb_no = plmdebtm.awb_no
                   and ehu_awb.from_city <> plmdebtm.data_no
                   and ehu_awb.dep = 'EI')
    where exists
               (select 1
                  from ehu_awb
                 where ehu_awb.awb_no = plmdebtm.awb_no
                   and ehu_awb.from_city <> plmdebtm.data_no
                   and ehu_awb.dep = 'EI');--10g可用merge
    merge into plmdebtm
    using ehu_awb on (ehu_awb.awb_no = plmdebtm.awb_no
                   and ehu_awb.from_city <> plmdebtm.data_no
                   and ehu_awb.dep = 'EI')
    when matched then
    update set plmdebtm.data_no=ehu_awb.from_city;
      

  2.   


    谢谢,上面的可以用,但是下面的那个语法不能用,出现错误的信息如下。ORA-38104:無法更新[ON 字句]中參照的資料欄:"PLMDEBTM"."DATA_NO"
      

  3.   

    ORA-38104:無法更新[ON 字句]中參照的資料欄:"PLMDEBTM"."DATA_NO"
    因为你的update子句中参照了连接条件中的列
    plmdebtm.data_no
    ehu_awb.from_city
      

  4.   

    merge语句中,update不能用于更新连接的列