[200分]程序块调用存储过程,展现游标的问题

zsq666 2009-03-13 05:57:31
create or replace package types
as
type p_cursor is ref cursor;---类型
end;

create or replace procedure query(v_sql varchar2,records out types.p_cursor)
as
begin
open records for all_sql;
end;


--通过程序块调用存储过程进行展现,但报"rs不是过程或尚未定义"错误
declare
allr number;
rs types.p_cursor;
begin
query('select * from dept',rs);
--如果只执行下面的输出,是正确的
dbms_output.put_line(rs%rowcount);
----执行下面报"rs不是过程或尚未定义"错误,为什么
for i in rs
loop
dbms_output.put_line(i.deptid||'---'||i.deptname);
end loop;

end;
...全文
70 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
jdsnhan 2009-03-18
  • 打赏
  • 举报
回复
declare
allr number;
rs types.p_cursor;
cid number;
cname varchar2(20);
begin
query('select custid,custname from cust',rs);
loop
fetch rs into cid,cname ;
exit when rs%notfound;
dbms_output.put_line(cid);
dbms_output.put_line(cname);
end loop;
close rs;
end;
zsq666 2009-03-17
  • 打赏
  • 举报
回复
三楼说的对,我疏忽写错了!我改过来了还是这个样子!?
create or replace package types
as
type p_cursor is ref cursor;---类型
end;

create or replace procedure query(v_sql varchar2,records out types.p_cursor)
as
begin
open records for all_sql;
end;


--通过程序块调用存储过程进行展现,但报"rs不是过程或尚未定义"错误
declare
allr number;
rs types.p_cursor;
begin
query('select * from dept',rs);
--如果只执行下面的输出,是正确的
dbms_output.put_line(rs%rowcount);
----执行下面报"rs不是过程或尚未定义"错误,为什么
for i in rs
loop
dbms_output.put_line(i.deptid||'---'||i.deptname);
end loop;

end;
ab5669 2009-03-13
  • 打赏
  • 举报
回复
3楼 正解
清风_X 2009-03-13
  • 打赏
  • 举报
回复
搂主太粗心,这么简单的错误都犯哦:)
codearts 2009-03-13
  • 打赏
  • 举报
回复
create or replace procedure query(v_sql varchar2,records out types.p_cursor)
as
begin
open records for all_sql;
end;

看看就知道错在哪 了
yf520gn 2009-03-13
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 yf520gn 的回复:]
query('select * from dept',:rs);
[/Quote]
看错了,不好意思!
yf520gn 2009-03-13
  • 打赏
  • 举报
回复
query('select * from dept',:rs);

17,082

社区成员

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

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