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/