Def*_*ore 9 sql database oracle database-design oracle10g
我在两个不同的数据库中有两个类似的oracle表.例如:我的表名是EMPLOYEE,主键是员工ID.具有相同列的相同表(例如,50列是两个数据库中的avlbl,并且链接了两个数据库).
我想逐列比较这两个表,找出哪些记录不匹配.我希望两个表中每行中的特定列不匹配.
mca*_*ral 15
select *
from
(
( select * from TableInSchema1
minus
select * from TableInSchema2)
union all
( select * from TableInSchema2
minus
select * from TableInSchema1)
)
Run Code Online (Sandbox Code Playgroud)
如果你想用查询来解决这个问题,应该这样做
作为一种替代方法,它可以避免对每个表进行两次完全扫描,并且还为您提供了一种简单的方法来判断哪个表的值组合比另一个表多:
SELECT col1
, col2
-- (include all columns that you want to compare)
, COUNT(src1) CNT1
, COUNT(src2) CNT2
FROM (SELECT a.col1
, a.col2
-- (include all columns that you want to compare)
, 1 src1
, TO_NUMBER(NULL) src2
FROM tab_a a
UNION ALL
SELECT b.col1
, b.col2
-- (include all columns that you want to compare)
, TO_NUMBER(NULL) src1
, 2 src2
FROM tab_b b
)
GROUP BY col1
, col2
HAVING COUNT(src1) <> COUNT(src2) -- only show the combinations that don't match
Run Code Online (Sandbox Code Playgroud)
信用在这里:http : //asktom.oracle.com/pls/apex/f?p=100 :11:0 ::::P11_QUESTION_ID : 1417403971710
| 归档时间: |
|
| 查看次数: |
108512 次 |
| 最近记录: |