Search notes:

Oracle: Compare the data of two tables

With a combination of the set operators union and minus, it is possible to execute an SQL statement that compares the data of two tables and returns their difference.
create table tq84_A (num  number, txt varchar2(10));
create table tq84_B (num  number, txt varchar2(10));
 
insert into tq84_A values(1, 'one'  );
insert into tq84_A values(2, 'two'  );
insert into tq84_A values(3, 'three');
insert into tq84_A values(4, 'four' );
 
insert into tq84_B values(1, 'one'  );
insert into tq84_B values(3, 'THREE');
insert into tq84_B values(4, 'four' );
insert into tq84_B values(5, 'five' );
 
select 'only A' where_, only_a.* from (select num, txt from tq84_A minus select num, txt from tq84_B) only_a union all
select 'only B' where_, only_b.* from (select num, txt from tq84_B minus select num, txt from tq84_A) only_b;
 
drop table tq84_A;
drop table tq84_B;
Of course, writing such an SQL statement is tedious. We should let Oracle create the SQL statement for us. An example of such a statement is here: Create an SQL Statement that compares two tables.

See also

dbms_comparison.
Determine the difference between the structure of two tables

Index