怎么调用存储过程的ref cursor类型输出参数返回的内容

ann790914 2007-10-22 01:28:17
有存储过程如下
create or replace package pck_test is
type out_cur is ref cursor;


create or replace procedure prc_test(
cur out pck_test.out_cur;
)
is
begin
open cur
for select 1 from dual;
end;
请问,我在oracle中怎么能够得到这个输出参数cur的内容呢?
...全文
189 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
47522341 2007-10-22
  • 打赏
  • 举报
回复
object与record类型不同的问题;^_^
create or replace procedure prc_test (
cur out pck_test.out_cur;
)
as
aobj typ_test := typ_test(null,null);
atbl tbl_test := tbl_test();
type rec is record(id varchar(10),name varchar(10));
ARec rec;
begin
for i in 1..6 loop
aobj.id := i;
aobj.name := 'name ' ¦ ¦i;
atbl.extend;
atbl(i) := aobj;
end loop;
open cur for
select * from table(cast(atbl as tbl_test));

loop
fetch cur into Arec;
exit when cur%notfound;
dbms_output.put_line(arec.id ¦ ¦arec.name);
end loop;
end;
ann790914 2007-10-22
  • 打赏
  • 举报
回复
请问,什么原因
ann790914 2007-10-22
  • 打赏
  • 举报
回复
我现在想知道的是,如果按照我写的存储过程的方式,用输出参数的话,怎么调用?
我是这么写的。
create type typ_test as object (id varchar(10),name varchar(10));
create type tbl_test as table of typ_test;

create package pck_test is
type out_cur is ref cursor;
end ;

create or replace procedure prc_test (
cur out pck_test.out_cur;
)
as
aobj typ_test := typ_test(null,null);
atbl tbl_test := tbl_test();
begin
for i in 1..6 loop
aobj.id := i;
aobj.name := 'name'||i;
atbl.extend;
atbl(i) := aobj;
end loop;
open cur for
select * from table(cast(atbl as tbl_test));

loop
fetch cur into aobj;
exit when cur%notfound;
dbms_output.put_line(aobj.id||aobj.name);
end loop;
end;


然后在执行存储过程的时候报错说【结果集变量或查询的类型不匹配】。


fxianxian 2007-10-22
  • 打赏
  • 举报
回复
這個是做開發在form里作為數據源的,要想在報表中調用的話,就要寫個函數
create or replace FUNCTION Frc_test RETURN pck_test.out_cur is
V_CURSOR pck_test.out_cur
begin
prc_test(V_CURSOR);
RETURN V_CURSOR;
end;

17,082

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧