Oracle MERGE Statement Guide
The MERGE statement in Oracle is used for merging data and can perform INSERT, UPDATE, and DELETE operations at the same time. Its basic syntax is as follows:
MERGE INTO target_table USING source_table
ON (merge_condition)
WHEN MATCHED THEN
UPDATE SET column1 = value1, column2 = value2
WHEN NOT MATCHED THEN
INSERT (column1, column2) VALUES (value1, value2);
One of which:
- target table: the table where the data will be merged.
- source_table: the table from which data is obtained
- merge_condition: merging condition, used to determine which rows in the source table and target table need to be merged.
- UPDATE SET: Modify the columns and their respective values when the conditions are met.
- INSERT operation to be executed when the conditions do not match.
Please ensure that the column names and data types of the source and target tables match when using the MERGE statement to avoid any merging errors.