Use the MERGE statement to select rows from one or more sources for update or insertion into a table or view. You can specify conditions to determine whether to update or insert into the target table or view.
This statement is a convenient way to combine multiple operations. It lets you avoid multiple INSERT, UPDATE, and DELETE DML statements.
MERGE is a deterministic statement. You cannot update the same row of the target table multiple times in the same MERGE statement.
Prerequisites
You must have the INSERT and UPDATE object privileges on the target table and the READ or SELECT object privilege on the source table. To specify the DELETE clause of the merge update clause, you must also have the DELETE object privilege on the target table.
Semantics
INTO Clause
Use the INTO clause to specify the target table or view you are updating or inserting into. In order to merge data into a view, the view must be updatable.
Restriction on Target Views
You cannot specify a target view on which an INSTEAD OF trigger has been defined.
USING Clause
Use the USING clause to specify the source of the data to be updated or inserted. The source can be a table, view, or the result of a subquery.
ON Clause
Use the ON clause to specify the condition upon which the MERGE operation either updates or inserts. For each row in the target table for which the search condition is true, Oracle Database updates the row with corresponding data from the source table. If the condition is not true for any rows, then the database inserts into the target table based on the corresponding source table row.