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!

Moving rows to destination table and deleting from source in one go?

805614eb-dada-4bac-8a92-c1e3b1a82a3aJul 24 2017 — edited Jul 26 2017

Is it possible to move rows from a source table to a destination table and then deleting the same rows from the source table in one statement ?

Something like this would be ideal, but I know "DELETE" cannot be use in "WHEN NOT MATCHED" clause... any suggestion please?

MERGE INTO destination_table d

USING (select *

         from source_table

        where  conditions ) s

ON (s.ID = d.ID)

WHEN NOT MATCHED THEN

    INSERT (field1_d, field2_d)

    VALUES (fields_d, field2_s)

    DELETE WHERE 1 = 1;

Thanks

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 23 2017
Added on Jul 24 2017
21 comments
4,038 views