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;
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;
相关文章推荐
- linux grep命令详解
- SUID、SGID详解
- 动态规划之n个元素出栈顺序种数
- 本宝宝的VIM_Pulgin
- DNS 查找失败,因此找不到 ******* 的服务器
- SERVLET 学习笔记
- 数据库中的三级模式结构
- 二. 模式匹配
- SQL自定义函数 字符串截取 递归查询 以及一个小例子
- Java中死锁的检测
- TokuMX will not run with transparent huge pages enabled.
- MongoDB
- php乱码问题
- oracle 10g和11g下 CDC机制(change data capture) 变化数据捕捉
- 服务与线程的区别
- BigDecimal用法详解
- 171. Excel Sheet Column Number
- GLFW Keyboard keys
- Dmp文件导入(Imp命令)
- Swift 学习指南