Oracle集合

来源:互联网 发布:mac vim 编辑:程序博客网 时间:2024/06/16 05:21
集合(查询效率较高):
1.Intersect(交集):返回两个查询共有的记录。
例如:select deptno from scott.emp Intersect select deptno from scott.dept;结果是两个表之间的共同值。
2.Union all(并集):返回各个查询的所有记录,包括重复记录。
例如:select deptno from scott.emp union all select deptno from scott.dept;
3.Union(并集):返回各个查询的所有记录,不包括重复记录。
例如:select deptno from scott.emp union select deptno from scott.dept;
4.Minus(补集):返回第一个查询检索出的记录减去第二个查询检索出的记录之后剩余的记录。
例如:select deptno from a minus select deptno from b;(a表存在该数据,b表不存在;
(1,2,3)和(2,4)是(1,3,4))。
5.order by和group by句子可以同时出现,一般是group by在前,先分组后排序。
6.根据结果集创建表(约束复制不了):create table 表名 as select 语句,insert 向表中插入一个结果集(insert int infos2 select * from infos),要求结果集中每一列的数据类型必须与表中的每一列的数据类型相同。
7.复制表结构:create table infos2 as select * from infos where 1=2;

原创粉丝点击