Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

MERGE Statment not updating the existing row

965816Jan 21 2016 — edited Jan 21 2016

Hi all,

I need your help guys, i am facing an issue with the merge statement find the sample program here,

i have table TEST1 with C1 and C2 are columns and on C1 we have a primary key.

create table test1 (c1 number(5), c2 number(5));

alter  table test1 add primary key (c1);

MERGE INTO test2 target

USING (SELECT 1 c1, 2 c2

         FROM dual

       UNION ALL

       SELECT 2, 2

         FROM dual

       UNION ALL

       SELECT 2, 2

         FROM dual

       UNION ALL

       SELECT 2, 1

         FROM dual) SOURCE

ON (target.c1 = source.c1)

WHEN MATCHED THEN

    UPDATE SET c2 = source.c2

WHEN NOT MATCHED THEN

    INSERT (c1, c2) VALUES (source.c1, source.c2);

when we are executing the merge statement i am facing violation of unique constraint.

Can any one help to resolve the issue?

Thank you all..

This post has been answered by Etbin on Jan 21 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 18 2016
Added on Jan 21 2016
4 comments
2,575 views