In the Target table there is a PK column usr_cd
which doesn't exist in the Source table. Hence, while inserting from Source to Target I want to generate a unique code. How can I achieve this when I am using MERGE
statement?
Following options are tried without luck:
- Sequence object: Can't use inside
MERGE
. - SP call: Can't execute SP inside
MERGE
inINSERT
. - Function call: Won't help as I can't use sequence object inside UDF. Also if I store a unique value in a table, I won't be able to update inside UDF.
- Adding code in Source table: Can't be used as some records will be updated and some will be inserted, hence it will break the sequence.
Adding default to Target table is one option but I want to avoid that.
Let me know if there is any other way of achieving this while using MERGE
.