DECLARE
STR VARCHAR2(50);
P_NO NUMBER(10);
BEGIN
MERGE INTO TEST2 T2
USING (SELECT T3.NAME, T3.DEPT, T3.BIRTHDAY
FROM TEST3 T3
WHERE T3.BIRTHDAY = DATE '2014-05-01') V
ON (V.NAME = T2.C2)
WHEN MATCHED THEN
UPDATE SET T2.C3 = V.BIRTHDAY, T2.C1 = 86868
WHEN NOT MATCHED THEN
INSERT (T2.C1, T2.C2, T2.C3) VALUES (11111, V.NAME, V.BIRTHDAY);
--MERGE INTO TEST2 为目票表将要操作的表,USING 后的SQL为数据源, ON 为条件 V.NAME 是不是等于 T2.C2
-- WHEN MATCHED THEN 为如果 V.NAME = T2.C2 就执行 WHEN MATCHED THEN 后的内容,如果 V.NAME 不等于 T2.C2 就执行 WHEN NOT MATCHED THEN 后的内容
-- WHEN MATCHED THEN 和 WHEN NOT MATCHED THEN 也可以只有一个。
--SELECT LEVEL INTO P_NO FROM TEST2 CONNECT BY LEVEL < 2;
END;