Skip to content
Advertisement

MERGE table, do nothing when matched

I have a table DOMAINS in 2 different schemas with columns ID, NAME,CODE,DESCRIPTION.

For any NAME exist in new schema, it should use existing ID without any merge; for those new NAME records, it should insert with ID from old schema.

How can i intepret the portion of do nothing in above query?

Advertisement

Answer

For your case, no need to use the part:

WHEN MATCHED THEN UPDATE ...

( using WHEN MATCHED THEN UPDATE SET a.id = a.id is accepted(Oracle doesn’t hurl) but has no impact, so, such a usage is redundant, because you don’t want to change anything for the matching case. )

If you wanted to change, then add

WHEN MATCHED THEN UPDATE SET a.id = b.id

before WHEN NOT MATCHED THEN INSERT...

( e.g.Oracle supports WHEN MATCHED THEN UPDATE syntax. Refer the Demo below )

Go on with the following for the current case :

Demo

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement