You are on page 1of 1

Merge Statements

The new Oracle 9i merge statement enables you to conditionally insert a


new row or update an existing row in the destination table without
having to use PL/SQL. All the hard work is done by database itself, you
just have to specify the source and destination tables.

Example:

MERGE INTO customers old


USING cust_changes new
ON (new.cust_id=old.cust_id)
WHEN MATCHED THEN
UPDATE SET old.cust_name=new.cust_name,
old.cust_addr=new.cust_addr;
WHEN NOT MATCHED THEN
INSERT (cust_id,cust_name,cust_addr)
VALUES (new.cust_id,new.cust_name,new.cust_addr);

You might also like