oracle函数之 minus
“minus”直接翻译为中文是“减”的意思,在Oracle中也是用来做减法操作的
Oracle的minus是按列进行比较的,所以A能够minus B的前提条件是结果集A和结果集B需要有相同的列数,且相同列索引的列具有相同的数据类型。此外,Oracle会对minus后的结果集进行去重,即如果A中原本多条相同的记录数在进行A minus B后将会只剩一条对应的记录.
Create table A(A1 number(12),A2 varchar2(50)); Create table B(B1 number(12),B2 varchar2(50)); Insert Into A Values (1,'a'); Insert Into A Values (2,'ba'); Insert Into A Values (3,'ca'); Insert Into A Values (4,'da'); insert into A Values(7,'a'); Insert Into B Values (1,'a'); Insert Into B Values (2,'bba'); Insert Into B Values (3,'ca'); Insert Into B Values (5,'dda'); Insert Into B Values (6,'Eda'); insert Into B Values(7,'a'); select * from a; select * from b; select * from a minus select * from b
显示结果:
如果是查询 select a2 from a minus select b2 from b
显示结果: