Database

January 08, 2023

by Administrator

MERGE INTO target_table a
USING source_table b
ON (a.id=b.id) --join condition
    WHEN MATCHED THEN
        UPDATE SET col1 = value1, col2 = value2,...
        [WHERE <update_condition>]
        [DELETE WHERE <delete_condition>] 
    WHEN NOT MATCHED THEN
        INSERT (col1,col2,...)
        values(value1,value2,...)
        WHERE <insert_condition>;
MERGE INTO target_table a
USING source_table b
ON (a.p_id=b.id)
    WHEN MATCHED THEN
        UPDATE SET a.parent_name = b.name
        WHERE a.parent_name is null;
COMMIT;

The destination source can either be a table name or a script

 

MERGE INTO target_table a
USING (select id,parent_name from source_table) b
ON (a.p_id=b.id)
    WHEN MATCHED THEN
        UPDATE SET a.parent_name = b.name
        WHERE a.parent_name is null;
COMMIT;

 


Originally posted on medium


References

https://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm#SQLRF01606

https://oracle-base.com/articles/9i/merge-statement

https://www.oracletutorial.com/oracle-basics/oracle-merge/

 

 



Comments

Your email address will not be published. All fields are required

Comment*
Name *
Email *
FEzgnhTQxci
Dec 07 2023, 09:05 PM

YDwIceAM

MAmhdKsHpNa
Dec 07 2023, 09:05 PM

JhnBlLTKGkIzq

pYAwyOJLfd
Dec 15 2023, 06:40 AM

vmRNXKSqWGJQkM

bmqGgtsHrpu
Dec 15 2023, 06:40 AM

TZGDYkahtKJ

ihyVUexcRuO
Feb 05 2024, 09:17 AM

wOgscbzKGxhS

ihyVUexcRuO
Feb 05 2024, 09:17 AM

wOgscbzKGxhS

ThAUOQnmDxzkPaH
Feb 13 2024, 08:13 AM

tqMgKXIYErsome

mvVeikqPbof
Feb 21 2024, 10:19 PM

VOQCBLfcapZte