CREATE OR REPLACe PROCEDURE PROC_PAGE_EMP(O_EMP_DATA OUT SYS_REFCURSOR, --分页数据
O_TOTAL_PAGE OUT NUMBER, --总页数
I_PAGE_INDEX NUMBER, --当前页面数
I_PAGE_SIZE NUMBER --每页展示的数据量
) AS
V_COUNT NUMBER;
v_pre NUMBER;
v_next NUMBER;
v_sql VARCHAr2(2000);
BEGIN
--查询总记录数
EXECUTE IMMEDIATE 'select count(*) from employees'
INTO V_COUNT;
--获取总页数
SELECt DECODE(MOD(V_COUNT, I_PAGE_SIZE),0,(V_COUNT / I_PAGE_SIZE),TRUNC(V_COUNT / I_PAGE_SIZE) + 1)
INTO O_TOTAL_PAGE
FROM DUAL;
v_pre := (((I_PAGE_INDEX - 1) * I_PAGE_SIZE) + 1);
v_next := I_PAGE_INDEX * I_PAGE_SIZE;
v_sql := 'SELECt * FROM (
SELECt ROWNUM AS r , e.* FROM (
SELECt * FROM employees
) e
) WHERe r BETWEEN ' || v_pre || ' AND ' || v_next;
OPEN O_EMP_DATA FOR v_sql;
END PROC_PAGE_EMP;
--分页存储过程开始执行
declare
v_employee employees%rowtype;
o_emp_data sys_refcursor;
o_total_page number;
v_id number;
begin
proc_page_emp(o_emp_data, o_total_page, 2, 8);
dbms_output.put_line(o_total_page);
loop
fetch o_emp_data
into v_employee;
dbms_output.put_line(v_employee.id);
exit when o_emp_data%notfound;
end loop;
close o_emp_data;
end;
最后返回的错误提示是:数据类型不一致:应为-,但却获得-
oracle存储过程返回游标类型是为什么不能把游标放到rowtype的变量中
答案:2 悬赏:60 手机版
解决时间 2021-01-25 08:52
- 提问者网友:缘字诀
- 2021-01-24 14:17
最佳答案
- 五星知识达人网友:胯下狙击手
- 2021-01-24 15:42
SELECt * FROM (
SELECt ROWNUM AS r , e.* FROM (
SELECt * FROM employees
) e
) WHERe r BETWEEN ' || v_pre || ' AND ' || v_next;
结果集里面多了一个r
SELECT ROWNUM AS r
SELECt ROWNUM AS r , e.* FROM (
SELECt * FROM employees
) e
) WHERe r BETWEEN ' || v_pre || ' AND ' || v_next;
结果集里面多了一个r
SELECT ROWNUM AS r
全部回答
- 1楼网友:污到你湿
- 2021-01-24 16:28
declare cursor c is select name,age,gendar from t; r t%rowtype;
v_name ....;
v_age ....;
v_gendar ....;begin for r in c loop
v_name := c.name;
v_age := c.age;
v_gendar := c.gendar; --其实不用再声明变量了,直接使用c.name,c.age,c.gendar即可
end loop;end;
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯