Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: How to Determine Whether to Insert or Update
Kenneth Koenraadt wrote:
> On Sun, 13 Mar 2005 06:59:37 -0500, Serge Rielau <srielau_at_ca.ibm.com>
> wrote:
>
>
>>>Avi. >> >>take a peek at the MERGE statement. >> >>Cheers >>Serge >> >>-- >>Serge Rielau >>DB2 SQL Compiler Development >>IBM Toronto Lab
MERGE
INTO CHILD
USING (SELECT P_ID AS ID, P_ID_ORDERING AS ORDERING
FROM DUAL) AS S
ON (S.ID = CHILD.PARENT_ID
AND S.ORDERING = CHILD.ORDERING)
WHEN NOT MATCHED THEN UPDATE SET <whatever>
WHEN MATCHED THEN INSERT VALUES (...)
Am I missing something?
Note that there is nothing in the docs stating the ON clause must refer to the source. FWIW I think the source could be DUAL straight up.
MERGE
INTO CHILD
USING DUAL
ON (P_ID = CHILD.PARENT_ID
AND P_ORDERING = CHILD.ORDERING)
WHEN NOT MATCHED THEN UPDATE SET <whatever>
WHEN MATCHED THEN INSERT VALUES (...)
Sometimes I wonder whether USING should be made optional....
Cheers
Serge
-- Serge Rielau DB2 SQL Compiler Development IBM Toronto LabReceived on Sun Mar 13 2005 - 07:49:19 CST