Oracle merge statement and by source/target condition

删除回忆录丶 提交于 2020-02-05 07:37:48

问题


I need to do a MERGE in Oracle, but I'm stuck.

In SQL Server, I always use the BY SOURCE and BY TARGET condition to check where record exists, and then take an action.

I'm a little confused because I don't know how to achieve the same in PL/SQL. I need to do a MERGE on two tables (customers and customers_stage).

  • If the record does not exists in the customer table - then insert.
  • If the record exits in both - then update.
  • If the record does not exists in customers_stage - then delete.

In SQL Server, it would look like this:

MERGE INTO dbo.Customers AS target
USING dbo.Customers_stage AS source ON target.ID = source.ExternalID

WHEN NOT MATCHED BY TARGET 
   THEN 
      INSERT

WHEN MATCHED 
   THEN
      UPDATE

WHEN NOT MATCHED BY SOURCE 
   THEN
      DELETE

How to achieve the same functionality in Oracle? I use SQL Developer.

Thank you very much.

来源:https://stackoverflow.com/questions/48842872/oracle-merge-statement-and-by-source-target-condition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!