Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> MERGE command and order of inserts updates
Hi,
I get an Unique constraint violation for the following merge command
MERGE INTO destination D
USING ( SELECT * FROM DEP_ACCT
where UPDT_TS BETWEEN TO_DATE('&1','MM/DD/YYYY HH24:MI:SS') ANDTO_DATE('&2','MM/DD/YYYY HH24:MI:SS') ) S
WHEN MATCHED THEN UPDATE SET D.BNK_RTE_NB = S.BNK_RTE_NB, D.DEP_ACCT_NB = S.DEP_ACCT_NB, WHEN NOT MATCHED THEN INSERT (D.DEP_ACCT_ID,D.BNK_RTE_NB) VALUES(S.DEP_ACCT_ID,S.BNK_RTE_NB,S.DEP_ACCT_NB).
A unique constraint index is defined on columns BNK_RTE_NB and DEP_ACCT_NB on the source as well as the destination tables.
DEP_ACCT_ID is the primary key on source and destination tables.
Because of this constraint, it is important that updated records are merged prior to insertion of new records, especially when the combination of BNK_RTE_NB and DEP_ACCT_NB already exists in destination.
Questions:
What is the order of records, that the MERGE command performs the upserts ? Is it consistent can we rely on the order.
Will the order vary, depending on the number of records that the join returns ?
If I want to use MERGE command, what is the workaround for my problem(without reming the constraints, on destination) ?
Thanks in advance.
srini
Received on Fri Jul 29 2005 - 04:18:34 CDT