Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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.</p> <p>The query will return all rows that</p> <ul> <li>Exists in table1 but not in table2</li> <li>Exists in table2 but not in table1</li> <li>Exists in both tables, but have at least one column with a different value</li> </ul> <p>(common identical rows will be excluded).</p> <p>"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.</p> <pre><code>select pk ,decode(a.rowid, null, null, 'A') as a ,decode(b.rowid, null, null, 'B') as b ,a.col1, b.col1 ,a.col2, b.col2 ,a.col3, b.col3 ,... from table1 a full outer join table2 b using(pk) where decode(a.col1, b.col1, 1, 0) = 0 or decode(a.col2, b.col2, 1, 0) = 0 or decode(a.col3, b.col3, 1, 0) = 0 or ...; </code></pre> <p><strong>Edit</strong> Added example code to show the difference described in comment. Whenever one of the values contains NULL, the result will be different.</p> <pre><code>with a as( select 0 as col1 from dual union all select 1 as col1 from dual union all select null as col1 from dual ) ,b as( select 1 as col1 from dual union all select 2 as col1 from dual union all select null as col1 from dual ) select a.col1 ,b.col1 ,decode(a.col1, b.col1, 'Same', 'Different') as approach_1 ,case when a.col1 &lt;&gt; b.col1 then 'Different' else 'Same' end as approach_2 from a,b order by a.col1 ,b.col1; col1 col1_1 approach_1 approach_2 ==== ====== ========== ========== 0 1 Different Different 0 2 Different Different 0 null Different Same &lt;--- 1 1 Same Same 1 2 Different Different 1 null Different Same &lt;--- null 1 Different Same &lt;--- null 2 Different Same &lt;--- null null Same Same </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload