I have two similar tables in oracle in two different databases. For example : my table name is EMPLOYEE and primary key is employee id. The same table with same columns(say 50 columns are is avlbl in two databases and two databases are linked.
I want to compare these two tables column by column and find out which records are not matching. i want the specific column in each row in two tables that are not matching.
should do the trick if you want to solve this with a query
Try to use 3rd party tool, such as SQL Data Examiner which compares Oracle databases and shows you differences.
As an alternative which saves from full scanning each table twice and also gives you an easy way to tell which table had more rows with a combination of values than the other:
Credit goes here: http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1417403971710
Using the
minus
operator was working but also it was taking more time to execute which was not acceptable. I have a similar kind of requirement for data migration and I used theNOT IN
operator for that. The modified query is :This query executed fast. Also you can add any number of columns in the select query. Only catch is that both tables should have the exact same table structure for this to be executed.
It won't be fast, and there will be a lot for you to type (unless you generate the SQL from user_tab_columns), but here is what I use when I need to compare two tables row-by-row and column-by-column.
The query will return all rows that
(common identical rows will be excluded).
"PK" is the column(s) that make up your primary key. "a" will contain A if the present row exists in table1. "b" will contain B if the present row exists in table2.
Edit Added example code to show the difference described in comment. Whenever one of the values contains NULL, the result will be different.