Skip to Main Content

SQL Developer

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!

Formating of merge : merge_insert_clause

NorbertKlFeb 7 2018 — edited Feb 26 2018

Hello all,

i have some problem to format a merge statement as I want to . I tried to wrap my head around vadims blog posts about this topic but I fear they are above my pay grade. consider the following example.

MERGE INTO crew tgt USING ( SELECT

     crew_seqno

    ,inoutdte

    ,cardtype

    ,tfirstnm

                             FROM

     crew@xxx

                             WHERE

     TO_CHAR(

         create_date

        ,'YYYYMMDD'

     ) = p_create_date_yyyymmdd

)

src ON ( src.crew_seqno = tgt.crew_seqno )

     WHEN NOT MATCHED THEN INSERT (

         crew_seqno                   -- this should be lined up

               ,inoutdte              -- this should be lined up

            ,cardtype                 -- this should be lined up

        ,tfirstnm                     -- this should be lined up

     ) VALUES (

         src.crew_seqno               -- this should be lined up

                ,src.inoutdte         -- this should be lined up

            ,src.cardtype             -- this should be lined up

        ,src.tfirstnm                 -- this should be lined up

     )

WHEN MATCHED THEN UPDATE SET tgt.inoutdte = src.inoutdte

,tgt.cardtype = src.cardtype

,tgt.tfirstnm = src.tfirstnm;

It should look like this

MERGE INTO crew tgt USING ( SELECT

     crew_seqno

    ,inoutdte

    ,cardtype

    ,tfirstnm

                             FROM

     crew@xxx

                             WHERE

     TO_CHAR(

         create_date

        ,'YYYYMMDD'

     ) = p_create_date_yyyymmdd

)

src ON ( src.crew_seqno = tgt.crew_seqno )

     WHEN NOT MATCHED THEN INSERT (

         crew_seqno                  

        ,inoutdte             

        ,cardtype                

        ,tfirstnm                    

     ) VALUES (

         src.crew_seqno              

        ,src.inoutdte        

        ,src.cardtype            

        ,src.tfirstnm                

     )

WHEN MATCHED THEN UPDATE SET tgt.inoutdte = src.inoutdte

,tgt.cardtype = src.cardtype

,tgt.tfirstnm = src.tfirstnm;

How can I achieve this result ?

I use version 17.4

Thanks a lot for your help.

Norbert

This post has been answered by Vadim Tropashko-Oracle on Feb 7 2018
Jump to Answer

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 26 2018
Added on Feb 7 2018
2 comments
581 views