oracle中的集合的并运算,Oracle集合运算

Oracle8i的集合运算符共有4个(其他版本的没用过,估计只会多,不会少):

1. Minus

2. Union

3. Union All

4. Intersect

create or replace procedure PRC_COLLECT_TEST is

vn_count long :=0;

begin

select count(1) into vn_count from emp;

dbms_output.put_line('Rows in table emp is:' || vn_count);

/*minus:只取不重复的记录*/

select count(1) into vn_count

from (select t.*, t.rowid from emp t

minus

select s.*, s.rowid from emp s);

dbms_output.put_line('minus rows in table emp is:' || vn_count);

/*union: 取两个查询记录(去掉重复的)**/

select count(1)  into vn_count

from (select t.*, t.rowid from emp t

union

select s.*, s.rowid from emp s);

dbms_output.put_line('union rows in table emp is:' || vn_count);

/*union all: 取两个查询所有的记录(包括重复的)**/

select count(1) into vn_count

from (select t.*, t.rowid from emp t

union all

select s.*, s.rowid from emp s);

dbms_output.put_line('union all rows in table emp is:' || vn_count);

/*intersect: 只取重复的记录(相当于交集吧)*/

select count(1)into vn_count

from (select t.*, t.rowid from emp t

intersect

select s.*, s.rowid from emp s);

dbms_output.put_line('intersect rows in table emp is:' || vn_count);

end PRC_COLLECT_TEST;

/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值