【oracle】 差異表計算
阿新 • • 發佈:2019-02-08
建測試表
create table t_A ( id VARCHAR2(36) not null, name VARCHAR2(100), age NUMBER, sex VARCHAR2(2) ); insert into t_A (id, name, age, sex) values ('1', '1', 1, '1'); insert into t_A (id, name, age, sex) values ('2', '2', 2, '2'); commit; create table t_B ( id VARCHAR2(36) not null, name VARCHAR2(100), age NUMBER, clazz VARCHAR2(36) ); insert into t_B (id, name, age, clazz) values ('1', '1', 1, '1'); insert into t_B (id, name, age, clazz) values ('2', '2', 1, '3'); insert into t_B (id, name, age, clazz) values ('3', '3', 3, '3'); commit;
計算
--- select t.*,rowid from t_A t; select t.*,rowid from t_B t; --- /*1.比較表結構 */ (select column_name from user_tab_columns where table_name = 'T_A' minus select column_name from user_tab_columns where table_name = 'T_B') union (select column_name from user_tab_columns where table_name = 'T_B' minus select column_name from user_tab_columns where table_name = 'T_A'); /* 2.比較表資料 */ (select * from t_A minus select * from t_B) union (select * from t_B minus select * from t_A)