java程序对Oracle两张表结构相似的表的数据对比,具体如下

table_a{
A 主键,

B 字段,

C 字段,

D 字段,

E 字段

}

table_b{
A 主键,

B 字段,

C 字段,

D 字段,

E 字段
}
需求:对比 table_a 跟 table_b 的主键对比,得到结果 1.a表主键存在,b表不存在;2.a表主键不存在,b表存在;3.a表和b表都存在一样的主键,那么就 a表的B字段跟b表的B字段对比, a表的C字段跟b表的C字段对比 。可以在数据库方面使用函数、 存储过程等。还有 两张表的数据可能超过千万条,求各位大神有没有好的建议。
这边只能悬赏100,,分数还可以追加的

总结下需求是在B表中找到于A表一样的记录

因为存在主键A B表本身不会存在重复值,所以最多是一对一的存在。
千万条记录不适合一次性全部load出来
直接使用sql联合查询应该更适合select a.A from A a,B b where a.A=b.A and a.B=b.B and a.C=b.C and a.D=b.D and a.E=b.E;
温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-04-01
1: select * from table_b b where not exist (select 1 from table_a a where a.A = b.A)
2: select * from table_a a where not exist (select 1 from table_b b where a.A = b.A)
3: select * from table_a a where exist (select 1 from table_b b where a.A = b.A and a.B=b.B and a.C=b.C)
相似回答