as619864232 发表于 2013-1-14 08:55:43

oracle 集合运算

集合运算就是将两个或多个结果集组合成一个结果集。集合运算包括:
    INTERSECT(交集):返回两个查询共有的记录。
    UNION ALL(并集):返回各个查询的所有记录,包括重复记录。
    UNION(并集):返回各个查询的所有记录,不包括重复记录。
    MINUS(补集):返回第一个查询检索出的记录减去第二个查询检索出的记录之后剩余的记录。
 
当使用集合操作的时候,要注意:查询所返回的列数以及列的类型必须匹配,列名可以不同。
 
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 Connected as scottSQL> select deptno from dept; DEPTNO------    10    20    30    40 SQL> select deptno from emp; DEPTNO------    20    30    30    20    30    30    10    20    10    30    20    30    20    10 14 rows selected 代码演示:INTERSECT
SQL> select deptno from dept INTERSECT select deptno from emp; DEPTNO------    10    20    30 
代码演示:UNION ALL
SQL> select deptno from dept union all select deptno from emp; DEPTNO------    10    20    30    40    20    30    30    20    30    30    10    20    10    30    20    30    20    10 18 rows selectedSQL> select deptno from emp union all select deptno from dept; DEPTNO------    20    30    30    20    30    30    10    20    10    30    20    30    20    10    10    20    30    40 18 rows selected 
代码演示:UNIONO
SQL> select deptno from emp UNION select deptno from dept; DEPTNO------    10    20    30    40 
代码演示:MINUS
SQL> select deptno from dept MINUS select deptno from emp; DEPTNO------    40
页: [1]
查看完整版本: oracle 集合运算