Search code examples
databaseoracle-databaseplsqlrdbms

How to update the rows that are not identical in terms of data in a tableB from tableA given that table structure are same in oracle?


Basically I've two tables with almost 46 columns now I wanted some PL/SQL script that can update the row if found unequal from a source table A to table B ( which needs to be updated) there is one primary key on the basis of which comparison will take place and after that update if found unequal.


Solution

  • By using the MERGE I have came to the correct answer which is satisfying the requirements as mentioned in my question.

    MERGE INTO TABLE_A 
    USING 
    (
        SELECT * FROM TABLE_B
    ) T 
    ON 
    (
        TABLE_A.PK=TABLE_B.PK
    )
    WHEN MATCHED THEN UPDATE 
        SET TABLE_A.COL1 = T.COL1,
            ...
            TABLE_A COL46 = T.COL46;