问题遇到的现象和发生背景
编写存储过程调用时报错。
问题相关代码,请勿粘贴截图
1、定义了一个包
create or replace package testpackage as type test_cursor is ref cursor;
end testpackage;
2、编写了一个分页的存储过程
create or replace procedure my_fenye(TableName in varchar2, --分页的表名
PageSize in number, --一页显示的记录
PageNow in number, --显示第几页
myrows out number, --总记录数
myPageCount out number, --总页数
p_cursor out testpackage.test_cursor --返回的记录数
) is
v_sql varchar2(1000);
v_sql1 varchar2(1000);
v_begin number := (PageSize - 1) * PageNow + 1;
v_end number := PageSize * PageNow;
begin
v_sql := 'select * from (select a.*,rownum rn from (select * from ' ||
TableName || ') a where rownum <=' || v_end ||</span><br /><span style="display:inline-block;text-indent:2em;"> ') b where rn >=' || v_begin;
open p_cursor for v_sql;
v_sql1 := 'select count(1) from ' || TableName;
execute immediate v_sql1
into myrows;
if mod(myrows, PageSize) = 0 then
myPageCount := myrows / PageSize;
else
myPageCount := floor(myrows / PageSize) + 1;
end if;
end;
3、调用存储过程,把结果打印出来
declare
v_ref testpackage.test_cursor;
v_myrows number;
v_mypagecount number;
type my_table is table of emp%rowtype ;
v_mytable my_table;
begin
my_fenye('EMP', 4, 2, v_myrows, v_mypagecount, v_ref);
dbms_output.put_line('总记录数:' || v_myrows);
dbms_output.put_line('总的页数:' || v_mypagecount);
fetch v_ref bulk collect
into v_mytable;
for i in 1 .. v_mytable.count loop
dbms_output.put_line(v_mytable(i).ename || '+' || v_mytable(i).sal);
end loop;
end;
运行结果及报错内容
在调用时报错了,错误如下:
能帮忙解决为什么会报这个错误。