下列 MERGE 指定在 USING 子句中查询定义的派生的表为其源:
MERGE INTO customer c
USING (SELECT * from ext_customer e1, orders e2
WHERE e1.customer_num=e2.customer_num ) e
ON c.customer_num=e.customer_num AND c.fname=e.fname
AND c.lname=e.lname
WHEN NOT MATCHED THEN
INSERT (c.fname, c.lname, c.company, c.address1, c.address2,
c.city, c.state, c.zipcode, c.phone)
VALUES (e.fname, e.lname, e.company, e.address1, e.address2,
e.city, e.state, e.zipcode, e.phone)
WHEN MATCHED THEN
UPDATE SET c.fname = e.fname,
c.lname = e.lname,
c.company = e.company,
c.address1 = e.address1,
c.address2 = e.address2,
c.city = e.city,
c.state = e.state,
c.zipcode = e.zipcode,
c.phone = e.phone ;