Merge Tables Examples

Example 1

MERGE INTO payments p
USING new_payments np ON (p.id = np.id)
 WHEN NOT MATCHED THEN
INSERT (p.id, p.amount, p.currency, p.no, p.details)
VALUES (np.id, np.amount, np.currency, np.no, np.details);

Example 2

MERGE INTO payments p
USING new_payments np ON (p.id = np.id)
 WHEN NOT MATCHED THEN
WHEN MATCHED THEN UPDATE SET p.details = np.details;

Example 3

merge into customers c
using (select * from customers_details) cd
on (c.customer_id = cd.customer_id)
when matched then
    update set c.email = cd.email
when not matched then
    insert (c.customer_id, c.name, c.email)
    values(cd.customer_id, cd.name, cd.email);