易截截图软件、单文件、免安装、纯绿色、仅160KB

Oracle 中的Union、Union All、Intersect、Minus

众所周知的几个结果集集合操作命令,今天详细地测试了一下,发现一些问题,记录备考。 假设我们有一个表Student,包括以下字段与数据: drop table student;
create table student
(
id int primary key,
name nvarchar2(50) not null,
score number not null
);
insert into student values(1,'Aaron',78);
insert into student values(2,'Bill',76);
insert into student values(3,'Cindy',89);
insert into student values(4,'Damon',90);
insert into student values(5,'Ella',73);
insert into student values(6,'Frado',61);
insert into student values(7,'Gill',99);
insert into student values(8,'Hellen',56);
insert into student values(9,'Ivan',93);
insert into student values(10,'Jay',90);
commit;
Union和Union All的区别。
select *
from student
where id < 4
union
select *
from student
where id > 2 and id < 6
结果将是

1    Aaron    78

2    Bill    76

3    Cindy    89

4    Damon    90

5    Ella    73
如果换成Union All连接两个结果集,则返回结果是:

1    Aaron    78

2    Bill    76

3    Cindy    89

3    Cindy    89

4    Damon    90

5    Ella    73
可以看到,Union和Union All的区别之一在于对重复结果的处理。
接下来我们将两个子查询的顺序调整一下,改为
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00


相关文档:

Oracle维护常用SQL语句汇总


 如何远程判断Oracle数据库的安装平台
  select * from v$version;
  查看表空间的使用情况
  select sum(bytes)/(1024*1024) as free_space,tablespace_name
  from dba_free_space
  group by tablespace_name;
  SELECT A.TABLESPACE_NAME,A.BYTES TOTAL,B.BYTES USED, C.BYTES FREE,
  (B.BYTE ......

Oracle 连接 复习

SQL> select * from ta;
        ID NAME
---------- --------------------
         1 gorey
         2 gorey2
SQL> select * from tb;
        I ......

oracle删除表中所有的数据

示例一:delete from emp;
实例二:truncate table emp;
当使用delete删除时,虽然删除了表中的所有数据,但是没有释放表所占的空间,如果用户确定要删除表中所有数据,使用实例二语句速度更快。delete语句可以回退,但truncate语句操作不能回退,执行的时候要多加注意这一点。 ......

oracle事务处理

1.回退事务
最好设置一个保存点,例savepoint a,或者执行 exec dbms_transaction.savepoint('a')(执行前需要执行set serveroutput on语句);取消部分事务就可以使用rollback to a,或者执行exec dbms_transaction.rollback_savepoint('a');取消全部事务可以执行rollback,或者exec dbms_transaction.rollback;
2.只读事务
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号