首页 > 数据库技术 > 详细

Oracle merage into

时间:2021-04-20 13:41:25      阅读:22      评论:0      收藏:0      [点我收藏+]
-- 更新+插入
-- merge into x using() on() when matched then update set when not matched then insert ; 
merge into A_MERGE A USING (select B.id,B.name,B.year,B.city from B_MERGE B) C
ON(A.id=C.id)
when matched then
update SET A.name=C.name where C.city != ‘西安‘
when not matched then
insert(A.id,A.name,A.year) values(c.id,C.name,C.year) where C.city=‘西安‘;

-- 删除
-- merge into x using() on() when matched then update set when not matched then insert ; 
merge into MCD_CUSTGROUP_PROTECT_RECORDS t1
using (select PRODUCT_NO, PROTECT_ID, CREATE_USERID
       from MCD_CUSTGROUP_PROTECT_RECORDS_TMP
       WHERE PROTECT_ID = 2021041609480293) t2
on (t1.PROTECT_ID = t2.PROTECT_ID AND t1.PRODUCT_NO = t2.PRODUCT_NO)
when matched then
    update
    set t1.CREATE_USERID = t2.CREATE_USERID delete where t1.PRODUCT_NO = t2.PRODUCT_NO;-- delete条件必须在上面的on里有/update set 语句不能少

Oracle merage into

原文:https://www.cnblogs.com/brxHqs/p/14680060.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!