oracle diff: how to compare two tables?

后端 未结 12 1947
忘了有多久
忘了有多久 2021-01-31 03:22

Suppose I have two tables, t1 and t2 which are identical in layout but which may contain different data.

What\'s the best way to diff these two tables?

相关标签:
12条回答
  • 2021-01-31 03:49

    You may try dbForge Data Compare for Oracle, a **free GUI tool for data comparison and synchronization, that can do these actions over all database or partially.

    alt text

    0 讨论(0)
  • 2021-01-31 03:54

    For this kind of question I think you have to be very specific about what you are looking for, as there are many ways of interpreting it and many different approaches. Some approaches are going to be too big a hammer if your question does not warrant it.

    At the simplest level, there is "Is the table data exactly the same or not?", which you might attempt to answer with a simple count comparison before moving on to anything more complex.

    At the other end of the scale there is "show me the rows from each table for which there is not an equivalent row in the other table" or "show me where rows have the same identifying key but different data values".

    If you actually want to sync Table A with Table B then that might be relatively straightforward, using a MERGE command.

    0 讨论(0)
  • 2021-01-31 03:55

    Try This,

    alter session set "_convert_set_to_join"= true;

    The other alternative is to rewrite the SQL query manually [replacing the minus operator with a NOT IN subquery] evidences about 30% improvement in execution time .

     select * 
       from A 
        where (col1,col2,?) not in 
       (select col1,col2,? from B) 
       union all 
       select * from B 
      where (col1,col2,?) not in 
      (select col1,col2,? from A); 
    

    I have referred from this post click here

    0 讨论(0)
  • 2021-01-31 03:57

    Fast solution:

    SELECT * FROM TABLE1
    MINUS
    SELECT * FROM TABLE2
    

    No records should show...

    0 讨论(0)
  • 2021-01-31 03:57

    Try:

    select distinct T1.id
      from TABLE1 T1
     where not exists (select distinct T2.id
                         from TABLE2 T2
                        where T2.id = T1.id)
    

    With sql oracle 11g+

    0 讨论(0)
  • 2021-01-31 03:59

    You can try using set operations: MINUS and INTERSECT

    See here for more details:
    O'Reilly - Mastering Oracle SQL - Chapter 7 - Set Operations

    0 讨论(0)
提交回复
热议问题