oracle表结构和表内容差异比对
oracle中有三种集合操作,他们会把左边和右边的select 结果集进行集合操作.
- union 并集
- intersect 交集
- minus 差集
假设有如下两张表 STUDENT_A 和 STUDENT_B
create table STUDENT_A
(
id VARCHAR2(36) not null,
name VARCHAR2(100),
age NUMBER,
sex VARCHAR2(2)
); insert into STUDENT_A (id, name, age, sex)
values ('', 'bobo', 28, '');
insert into STUDENT_A (id, name, age, sex)
values ('', 'sisi', 29, '');
commit; create table STUDENT_B
(
id VARCHAR2(36) not null,
name VARCHAR2(100),
age NUMBER,
clazz VARCHAR2(36)
); insert into STUDENT_B (id, name, age, clazz)
values ('', 'bobo', 28, '');
insert into STUDENT_B (id, name, age, clazz)
values ('', 'sisi', 29, '');
insert into STUDENT_B (id, name, age, clazz)
values ('', 'kiki', 30, '');
commit;
效果图如下:
比较两表结构差异语句:
注意下面的小括号不能省,因为是从左到右计算的,如果省掉计算公式就不一样了哦,大家可以自行脑补.
(
SELECT column_name FROM user_tab_columns WHERE table_name = 'STUDENT_A'
MINUS
SELECT COLUMN_name FROM user_tab_columns WHERE table_name = 'STUDENT_B'
)
UNION
(
SELECT column_name FROM user_tab_columns WHERE table_name = 'STUDENT_B'
MINUS
SELECT COLUMN_name FROM user_tab_columns WHERE table_name = 'STUDENT_A'
)
结果图如下:
比较两表内容语句:
注意下面的小括号不能省,因为是从左到右计算的,如果省掉计算公式就不一样了哦,大家可以自行脑补.
(
SELECT * FROM STUDENT_A
MINUS
SELECT * FROM STUDENT_B
)
UNION
(
SELECT * FROM STUDENT_B
MINUS
SELECT * FROM STUDENT_A
)
结果图如下:
同上图可知比较内容的时候,是不关心字段名是否有差异的,它只关心字段的类型和值.