ITPub博客

首页 > 应用开发 > IT综合 > cursor express的一点测试!

cursor express的一点测试!

原创 IT综合 作者:warehouse 时间:2008-01-04 13:43:49 0 删除 编辑
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博客 ” ,链接:https://blog.itpub.net/19602/viewspace-996438/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2007-12-07

  • 博文量
    717
  • 访问量
    5366292