Chinaunix首页 | 论坛 | 博客
  • 博客访问: 246352
  • 博文数量: 14
  • 博客积分: 2015
  • 博客等级: 大尉
  • 技术积分: 902
  • 用 户 组: 普通用户
  • 注册时间: 2006-10-27 16:02
文章分类

全部博文(14)

文章存档

2009年(5)

2008年(9)

我的朋友

分类: LINUX

2008-07-24 16:43:02

在oracle的precedure要么使用cursor返回单个值(含单条记录),要么就使用ref cursor返回记录集。
 
如果是查询1个列,可以如下:

  2    cursor v_cur is
  3      select t2 from t;
  4  begin
  5     for v_t in v_cur
  6  loop
  7     dbms_output.put_line(v_t.t2);
  8  end loop;
  9  end;
 10  /
1
2
3
4
5
6
6
PL/SQL procedure successfully completed.

如果是个记录集可以如下:
create or replace procedure test(cr_test in out sys_refcursor)
is
  3  begin
  4     open cr_test for select * from t;
  5  end;
  6  /
Procedure created.
x refcursor
test(:x)
PL/SQL procedure successfully completed.
x
T1                                               T2
---------------------------------------- ----------
aa                                                1
bbb                                               2
?                                                 3
c                                                 4
T?                                               5
 6
dd                                                6
7 rows selected.

当然还有其他方法能返回,这里就不多啰唆了。
阅读(1150) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-03-27 17:33:23

那如果返回某一个数值呢

chinaunix网友2009-03-27 17:32:34

ff