I'm trying to execute a procedure that returns a sys_refcursor
, and I want to use a with command to get the cursor, but I get an error when I execute the proc. Is it possible? Below is the proc:
create or replace
procedure sp_proc(
p_vl_skip in number,
p_vl_take in number,
tblresult out sys_refcursor)
as
v_first_row number;
v_last_row number;
begin
select p_vl_skip into v_first_row from dual;
select p_vl_skip + p_vl_take into v_last_row from dual;
open tblresult for
with tbl_relacao_rejeicoes as (
select vl_value1, vl_value2, row_number() over (order by vl_value1 desc) v开发者_如何学Cl_reg
from tb_table
order by vl_value1 desc)
select *
from tbl_relacao_rejeicoes
where vl_reg between v_first_row and v_last_row
order by cd_motivo_rejeicao vl_value1;
end;
/
It compiles without any logs, but when I execute it, I get:
OracleException: ORA-06550: line 1, column 7:
PLS-00201: identifier 'TBL_RELACAO_REJEICOES' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Your second order by:
order by cd_motivo_rejeicao vl_value1;
is not valid. Is "cd_motivo_rejeicao" a column somewhere that you didn't select? If it is, put a comma between it and vl_value1. Otherwise, get rid of it. I'm also not sure why you've got the first ORDER BY in the WITH clause SELECT - it serves no purpose, does it? At any rate, I was able to get your procedure to run by fixing the second order by. So, yes you can use the WITH clause within a cursor.
精彩评论