问题
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