易截截图软件、单文件、免安装、纯绿色、仅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重载操作符的例子

转自:http://download.oracle.com/docs/cd/B13789_01/server.101/b10759/statements_6004.htm
Creating User-Defined Operators: Example
This example creates a very simple functional implementation of equality and then creates an operator that uses the function:
CREATE FUNCTION eq_f(a VARCHAR2, b VARCHA ......

sql2005 链接服务器 连接Oracle...

一、建立链接服务器
       有人喜欢调用系统过程来建立,但我个人对系统过程没有特别的学习 ,所以用的是界面设置,当然有兴趣也可以研究一下的,因为可以把SQL执行导出来。
USE [master]
GO
EXEC master.dbo.sp_addlinkedserver @server = N'TEST2', @srvproduct=N'ORCL', @provider=N ......

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号