存储过程返回结果集的问题

jjoulejcc 2011-11-17 11:03:56
创建了一个存储过程usp_getset,查看了一下user_procedures表,已经创建成功:

create or replace procedure usp_getset
(
acs_results out sys_refcursor
)
as
begin
open acs_results for
select * from employees;
end usp_getset;


但是在调用的时候报错,调用代码如下:

declare
cs_results sys_refcursor;
begin
usp_getset(cs_results);
for test in cs_results loop
dbms_output.put_line(test.employee_id);
end loop;
end;


系统提示:
ORA-06550: line 5, column 15:
PLS-00221: 'CS_RESULTS' is not a procedure or is undefined
ORA-06550: line 5, column 3:
PL/SQL: Statement ignored

麻烦大家看看是怎么回事呀,我接触oracle不久,谢谢
...全文
87 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
007-x 2011-11-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 benchim888 的回复:]
declare
cs_results sys_refcursor;
r_employees employees%rowtype;
begin
usp_getset(cs_results);
loop
fetch cs_results into r_employees;
exit when cs_results%not_found;
dbms_output.put_line(r_employees.employee_id);
end loop;
end;
[/Quote]
大奔哥手好快,捉虫来了exit when cs_results%notfound;
007-x 2011-11-17
  • 打赏
  • 举报
回复
ref cursor 不能用for循环,只能使用普通loop实现
DECLARE
cs_results sys_refcursor;
employees_row employees%ROWTYPE;
BEGIN
usp_getset (cs_results);

LOOP
FETCH cs_results
INTO employees_row;

EXIT WHEN cs_results%NOTFOUND;
DBMS_OUTPUT.put_line (employees_row.employee_id);
END LOOP;
close cs_results;
END;


jjoulejcc 2011-11-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 benchim888 的回复:]
SQL code


declare
cs_results sys_refcursor;
r_employees employees%rowtype;
begin
usp_getset(cs_results);
loop
fetch cs_results into r_employees;
exit when cs_results%not_fou……
[/Quote]

呵呵,学习了,谢谢
BenChiM888 2011-11-17
  • 打赏
  • 举报
回复

declare
cs_results sys_refcursor;
r_employees employees%rowtype;
begin
usp_getset(cs_results);
loop
fetch cs_results into r_employees;
exit when cs_results%not_found;
dbms_output.put_line(r_employees.employee_id);
end loop;
end;

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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