update select 语句和merge into语句

查看执行计划,发现merge语句比update预计效果高很多


update DW_MEMBER_D dset d.mem_grade=

(select e.grade_idfrom DW_MEMBER_exp ewhere e.card_no=d.card_no)



    update DW_HOTELORDER_F b

        set(contacter_mbl_pr, contacter_mbl_cty)=

            (select a.province, a.city

               from MOBILE_BELONGINGNESS_ORDER a

              where a.reser_no= b.reser_no)


update WC_CONCALL_A f

   set f.emp_wid = ( select c.empwid
                      from (select a.month_wid,
                                   a.postn_wid,
                                   b.emp_wid as empwid,
                                   a.prod_ln_wid /*, b.postn_type_cd_i*/
                              from WC_CONCALL_A a, wc_postn_hist_f b
                             where a.month_wid = b.month_wid
                               and a.postn_wid = b.postn_wid) c
                     where c.month_wid = f.month_wid
                       and c.postn_wid = f.postn_wid
                       and c.prod_ln_wid = f.prod_ln_wid
)
                       

    

MERGE INTO WC_CONCALL_A f

    using (select a.month_wid,
                  a.postn_wid,
                  b.emp_wid as empwid,
                  a.prod_ln_wid /*, b.postn_type_cd_i*/
             from WC_CONCALL_A a, wc_postn_hist_f b
            where a.month_wid = b.month_wid
              and a.postn_wid = b.postn_wid) c
    ON (c.month_wid = f.month_wid and c.postn_wid = f.postn_wid and c.prod_ln_wid = f.prod_ln_wid)
    WHEN MATCHED THEN
      UPDATE SET f.emp_wid = c.empwid

   


MERGE INTO ZZ_HAP p
USING (select 0 as row_wid,
              'NA' as code_id,
              1 lvl,
              1 par_id,
              'OTHER' en_name,
              '其他' cn_name,
              'Y' isleaf_flg,
              'Unspecified' long_name,
              'OTHER' datasource_type,
              'OTHER' integration_id,
              'en' lang_id,
              'N' src_delete_flg,
              'Y' active_flg,
              '999999' disp_order,
              to_date('19500101', 'yyyymmdd') src_eff_from_dt,
              to_date('99991231', 'yyyymmdd') src_eff_to_dt,
              to_date('19500101', 'yyyymmdd') created_on_dt,
              to_date('99991231', 'yyyymmdd') changed_on_dt,
              'Y' current_flg,
              to_date('19500101', 'yyyymmdd') begin_dt,
              to_date('99991231', 'yyyymmdd') end_dt,
              sysdate w_insert_dt,
              sysdate w_update_dt
         from dual) np
ON (p.row_wid = np.row_wid)
WHEN NOT MATCHED THEN

  insert( 
begin_dt                , 
end_dt                  , 
w_insert_dt             , 
w_update_dt              
   )
  VALUES
  (       
 np.begin_dt,            
 np.end_dt,              
 sysdate,                
 sysdate               
)
WHEN MATCHED THEN
  UPDATE
     SET 

         p.w_update_dt             = sysdate,
         p.master_partner_type     = np.code_id,
         p.partner_type            = np.code_id;


             

              mergeinto DW_ORDER_F aa

  using MOBILE_BELONGINGNESS_ORDER bb

  on   (aa.reser_no= bb.reser_noand aa.create_date_wid >=20160401and aa.create_date_wid <=20160701)

   whenmatchedthen

   update

    set aa.contacter_mbl_pr= bb.province, aa.contacter_mbl_cty= bb.city


--删除t1表中和t2表id相等的所有行

mergeinto test1 t1

using  test2 t2

on(t1.id= t2.id)

when matchedthen

  update set t1.name= t1.name --where只能出现一次,如果这里使用了where,delete后面的where就无效了。

 deletewhere t1.id=t2.id;



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值