Merge Code Sample – Oracle

It’s Oracle Script.

The Oracle MERGE statement selects data from one or more source tables and updates or inserts it into a target table. The MERGE statement allows you to specify a condition to determine whether to update data from or insert data into the target table.

Following is the Oracle Merge statement format.

MERGE INTO target_table
USING (source_table)
ON (search_condition)
    WHEN MATCHED THEN
        UPDATE SET col1 = value1, col2 = value2,...
        WHERE <update_condition>
        [DELETE WHERE <delete_condition>]
    WHEN NOT MATCHED THEN
        INSERT (col1,col2,...)
        values(value1,value2,...)
        WHERE <insert_condition>;

You can use select statement on (source_table).

Leave a Reply