3

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.

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
tylkonachwile
  • 2,025
  • 4
  • 16
  • 28

0 Answers0