【发布时间】:2020-09-14 02:52:05
【问题描述】:
我正在尝试使用 Oracle PL/SQL 存储过程在服务器端实现分页。
create or replace PROCEDURE SEARCH_CUST_RECIPIENTS(v_cust_id IN t_recipient.r_cust_id%TYPE,
v_recipient_id IN t_recipient.recipient_id%TYPE,
v_current_page IN NUMBER,
v_records_per_page IN NUMBER,
v_result_set OUT SYS_REFCURSOR,
v_total_records_found OUT NUMBER,
v_total_pages_no OUT NUMBER)
AS
TYPE lv_result_set_row_type IS RECORD (lrecipient_id t_recipient.recipient_id%TYPE,
lr_cust_id t_recipient.r_cust_id%TYPE,
lrecipient_name t_recipient.recipient_name%TYPE,
lrecipient_country t_recipient.recipient_country%TYPE,
lrecipient_state t_recipient.recipient_state%TYPE,
lrecipient_pincode t_recipient.recipient_pincode%TYPE,
lr_acc_number t_recipient.r_acc_number%TYPE,
lr_bank_name t_recipient.r_bank_name%TYPE);
lv_result_set_row lv_result_set_row_type;
BEGIN
OPEN v_result_set FOR
SELECT * FROM
(
SELECT t_temp_table.*, ROWNUM rnum
FROM
(
SELECT t_recipient.recipient_id,
t_recipient.r_cust_id,
t_recipient.recipient_name,
t_recipient.recipient_country,
t_recipient.recipient_state,
t_recipient.recipient_pincode,
t_recipient.r_acc_number,
t_recipient.r_bank_name
FROM t_recipient
WHERE r_cust_id=v_cust_id AND recipient_id LIKE v_recipient_id||'%' ORDER BY t_recipient.recipient_id
) t_temp_table
WHERE ROWNUM <= (v_current_page)*v_records_per_page
)
WHERE rnum > (v_current_page-1)*v_records_per_page;
IF v_result_set%ISOPEN THEN
LOOP
FETCH v_result_set INTO lv_result_set_row;
v_total_records_found := v_result_set%ROWCOUNT;
v_total_pages_no := ROUND(v_total_records_found/v_records_per_page);
END LOOP;
END IF;
END;
我无法弄清楚结果集的返回类型和定义的记录类型有什么问题,但是当我尝试将游标 v_result_set 提取到 lv_result_set_row 时,它给了我以下错误。
Connecting to the database ORACLR_CONNECTION_DATA_CMS.
ORA-06504: PL/SQL: Return types of Result Set variables or query do not match
ORA-06512: at "C##SCOTT.SEARCH_CUST_RECIPIENTS", line 42
ORA-06512: at line 15
Process exited.
【问题讨论】:
标签: oracle stored-procedures plsql pagination resultset