博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
oracle merge同时包含增、删、改
阅读量:6892 次
发布时间:2019-06-27

本文共 1161 字,大约阅读时间需要 3 分钟。

原来一直没注意,merge是可以支持delete,只不过必须的是on条件满足,也就是要求系统支持逻辑删除,而非物理删除。

Using the DELETE Clause with MERGE Statements

You may want to cleanse tables while populating or updating them. To do this, you may want to consider using the DELETE clause in a MERGE statement, as in the following example:

MERGE USING Product_Changes SINTO Products D ON (D.PROD_ID = S.PROD_ID)WHEN MATCHED THENUPDATE SET D.PROD_LIST_PRICE =S.PROD_NEW_PRICE, D.PROD_STATUS = S.PROD_NEWSTATUSDELETE WHERE (D.PROD_STATUS = "OBSOLETE")WHEN NOT MATCHED THENINSERT (PROD_ID, PROD_LIST_PRICE, PROD_STATUS)VALUES (S.PROD_ID, S.PROD_NEW_PRICE, S.PROD_NEW_STATUS);

Thus when a row is updated in products, Oracle checks the delete condition D.PROD_STATUS = "OBSOLETE", and deletes the row if the condition yields true.

The DELETE operation is not as same as that of a complete DELETE statement. Only the rows from the destination of the MERGE can be deleted. The only rows that are affected by the DELETE are the ones that are updated by this MERGE statement. Thus, although a given row of the destination table meets the delete condition, if it does not join under the ON clause condition, it is not deleted.

 

 

转载地址:http://olzdl.baihongyu.com/

你可能感兴趣的文章
Ubuntu 12.04 安装 gcc-4.8 及 gdb 7.6
查看>>
GII 和 DEBUG 模块出现 403 解决
查看>>
shell历史命令记录功能
查看>>
kali linux软件源
查看>>
cocos2d_x在windows环境下的方向键支持
查看>>
Maven学习总结(11)——Maven Tomcat7自动部署
查看>>
zabbix安装界面报连接不到数据
查看>>
pjsip 同时使用多套音频设备
查看>>
DevOps:怎么实现源代码注释和系统文档的自动化更新?
查看>>
make 中的路径搜索(十二)
查看>>
zabbix agent 端主动注册
查看>>
初识Mysql(二)
查看>>
监控系统的状态
查看>>
Samba文件共享服务
查看>>
软件目录开发规范
查看>>
compute post expression
查看>>
C#中DataTable中的Compute方法使用收集
查看>>
Python——特殊属性与方法
查看>>
Python pip 报错
查看>>
POJ2187:Beauty Contest——题解
查看>>