cursor express的一点测试!

http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/expressions6a.htm#1033378[@more@]

SQL> create table t(id int , name varchar2(10) , salary number(10,2));

表已创建。

SQL> insert into t values(1 , 'a' , 1000);

已创建 1 行。

SQL> insert into t values(2 , 'b' , 2000);

已创建 1 行。

SQL> insert into t values(3 , 'c' , 3000)
2 ;

已创建 1 行。

SQL> commit;

提交完成。

--利用sys_refcursor定义的输入ref cursor变量定义一个函数处理结果集之后才返回想要的结果

SQL> create or replace function f(p_result sys_refcursor)
2 return integer
3 is
4 v_salary number ;
5 v_id int;
6 v_count int default 0 ;
7 begin
8 loop
9 fetch p_result into v_id , v_salary ;
10 exit when p_result%notfound ;
11 if mod(v_id , 2) <>0 then
12 v_count := v_count + 1 ;
13 else
14 null ;
15 end if ;
16 end loop ;
17 return(v_count);
18
19 end ;
20 /

函数已创建。

SQL> select * from t a where f(cursor(select id , salary from t b
2 where a.id = b.id ))>0;

ID NAME SALARY
---------- ---------- ----------
1 a 1000
3 c 3000

--利用cursor express直接输出结果

SQL> select cursor(select * from t where mod(id , 2)<>0) from dual;

CURSOR(SELECT*FROMTW
--------------------
CURSOR STATEMENT : 1

CURSOR STATEMENT : 1

ID NAME SALARY
---------- ---------- ----------
1 a 1000
3 c 3000

--直接取数
SQL> select * from t where mod(id ,2)<>0 ;

ID NAME SALARY
---------- ---------- ----------
1 a 1000
3 c 3000

SQL>

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/19602/viewspace-996438/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/19602/viewspace-996438/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值