您的位置:首页 > 其它

update select 语句和merge into语句

2016-04-19 17:25 183 查看
查看执行计划,发现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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: