日期:2014-05-16  浏览次数:20845 次

批量更新
select a.mp_id mp_id,
  a.org_no mp_org,
  b.org_no meter_org,
  b.meter_id meter_id,
  d.cons_no cons_no
  from c_mp a, c_meter b, c_meter_mp_rela c, c_cons d
 where a.mp_id = c.mp_id
  and b.meter_id = c.meter_id
  and a.cons_id = d.cons_id
  and a.org_no <> b.org_no;

如果length(a.org_no)>length(b.org_no)的话,则更新C_METER里面的ORG_NO更新成C_MP的ORG_NO,这个批量更新语句该怎么写

------解决方案--------------------
merge into c_meter b
using (select a.org_no , c.meter_id
from c_mp a, c_meter_mp_rela c
where a.mp_id = c.mp_id) a
on b.meter_id = a.meter_id
when matched then
update set b.org_no = a.org_no where length(a.org_no) > length(b.org_no)