Comparing records in duplicate tables in different oracle databases

后端 未结 2 1168
野的像风
野的像风 2021-01-26 04:17

I have the same table in two oracle databases. One is a staging database that has it\'s record loaded into the primary. I want to go through the staging table and see if there a

相关标签:
2条回答
  • 2021-01-26 04:58

    Something like this should work

    delete from stagingtable
    where id in
    (select id
    from stagingtable st join productiontable pt on st.id = pt.id
    and st.nextfield = pt.nextfield
    etc
    )
    
    0 讨论(0)
  • 2021-01-26 05:02

    To get the ones where something has changed you can use:

    SELECT * FROM "staging_table"
    MINUS
    SELECT * FROM "table";
    

    So, assuming that the table has a primary key then you can do

    DELETE FROM "table"
    WHERE primary_key_column
          NOT IN 
          ( SELECT primary_key_column
            FROM (
              SELECT * FROM "staging_table"
              MINUS
              SELECT * FROM "table"
            )
          );
    
    0 讨论(0)
提交回复
热议问题