zoukankan      html  css  js  c++  java
  • oracle merge同时包含增、删、改

    原来一直没注意,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 S
    INTO Products D ON (D.PROD_ID = S.PROD_ID)
    WHEN MATCHED THEN
    UPDATE SET D.PROD_LIST_PRICE =S.PROD_NEW_PRICE, D.PROD_STATUS = S.PROD_NEWSTATUS
    DELETE WHERE (D.PROD_STATUS = "OBSOLETE")
    WHEN NOT MATCHED THEN
    INSERT (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.

     
  • 相关阅读:
    mysql 主从复制
    通过git-bash 批量管理VMware虚拟机
    MySQL基础
    lnmp架构
    搭建yum仓库服务器
    什什么是集群?么是分布式?
    nginx介绍1
    网络抓包工具 wireshark 入门教程
    DNS原理总结及其解析过程详解
    PetaPoco中使用Exists
  • 原文地址:https://www.cnblogs.com/zhjh256/p/9977828.html
Copyright © 2011-2022 走看看