Oracle - difference or change between two rows from two tables

I have two tables have the same scheme, one of which will have records of the previous day, the others will have current. I want to compare both and find only changes or only rows that have different meanings in at least one column.

How is this possible in pl / sql, oracle? (I did something similar using checksum in T-SQL, but not sure how to do it in pl / sql)

+3
source share
3 answers

This SO answer provides a very efficient solution that uses Oracle to compare the results of two queries: Checking SQL Query Equivalence

+3

- , (A-B) U (B-A):

(SELECT * FROM TODAY_TABLE
MINUS
SELECT * FROM YESTERDAY_TABLE)
UNION ALL
(SELECT * FROM YESTERDAY_TABLE
MINUS
SELECT * FROM TODAY_TABLE)

, , , .

+3

As Dougman published one of the most effective ways to compare two datasets is GROUP them. I usually use this query to compare two tables:

SELECT MIN(which), COUNT(*), pk, col1, col2, col3, col4
  FROM (SELECT 'old data' which, pk, col1, col2, col3, col4
           FROM t
         UNION ALL
         SELECT 'new data' which, pk, col1, col2, col3, col4 FROM t_new)
 GROUP BY pk, col1, col2, col3, col4
HAVING COUNT(*) != 2
 ORDER BY pk, MIN(which);
+3
source

Source: https://habr.com/ru/post/1720508/


All Articles