-- MERGE INTO TEST
C REATE TABLE MERGE_TEST
(INT1 INT,
INT2 INT,
VAL VARCHAR(100) )
MERGE INTO MERGE_TEST MG
USING (SELECT 1 AS INT1, 1 AS INT2, 'AAA' AS VAL) A
ON (MG.INT1 = A.INT1 AND MG.INT2 = A.INT2)
WHEN MATCHED THEN
UPDATE SET
VAL = A.VAL
WHEN NOT MATCHED THEN
INSERT
(INT1, INT2, VAL)
VALUES
(A.INT1, A.INT2, A.VAL)
;
SELECT * FROM MERGE_TEST;
INT1 INT2 VAL
----------- ----------- -------------------------------------------
1 1 AAA
(1개 행 적용됨)
MERGE INTO MERGE_TEST MG
USING (SELECT 1 AS INT1, 1 AS INT2, 'BBB' AS VAL) A
ON (MG.INT1 = A.INT1 AND MG.INT2 = A.INT2)
WHEN MATCHED THEN
UPDATE SET
VAL = A.VAL
WHEN NOT MATCHED THEN
INSERT
(INT1, INT2, VAL)
VALUES
(A.INT1, A.INT2, A.VAL)
;
SELECT * FROM MERGE_TEST;
INT1 INT2 VAL
----------- ----------- -------------------------------------------
1 1 BBB
(1개 행 적용됨)