Tuesday 5 March 2013

Merge Statement


The MERGE statement merges data of one table with that of another table. It uses the MATCH condition to determine the existence of the rows. If the given row exists, then it updates the row. Otherwise, it inserts the row.

MERGE INTO employee e
    USING hr_records h
    ON (e.id = h.emp_id)
  WHEN MATCHED THEN
    UPDATE SET e.address = h.address
  WHEN NOT MATCHED THEN
    INSERT (id, address)
    VALUES (h.emp_id, h.address);

No comments:

Post a Comment