hmz349853714 2022-09-08 21:46
浏览 32
已结题

存储过程执行时报ORA-00932错误

问题遇到的现象和发生背景

编写存储过程调用时报错。

问题相关代码,请勿粘贴截图

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;

运行结果及报错内容

在调用时报错了,错误如下:

img


能帮忙解决为什么会报这个错误。

  • 写回答

1条回答 默认 最新

  • hmz349853714 2022-09-08 22:22
    关注

    问题解决了。

    v_sql := 'select empno,ename,job,mgr,hiredate,sal,comm,deptno from (select a.*,rownum rn from (select * from ' ||
    TableName || ') a where rownum <=' || v_end ||
    ') b where rn >=' || v_begin;

    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 9月16日
  • 创建了问题 9月8日

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用