SP2-0625: 打印变量 SYS_REFCURSOR 时出错

huangapple go评论63阅读模式
英文:

SP2-0625: Error printing variable SYS_REFCURSOR

问题

I suspect there is some issue with the cursor itself , because it all started when I got ORA-01001 Invalid Cursor.

英文:
This is a minimal example:

I suspect there is some issue with the cursor itself , because it all started when I got ORA-01001 Invalid Cursor

create or replace
package TABULA.gettorim as 
PROCEDURE liorByBranch ( br_out_rec        OUT sys_refcursor );
end gettorim;
/
Package created.
CREATE OR REPLACE PACKAGE BODY tabula.gettorim AS
    PROCEDURE liorbybranch (
        br_out_rec      OUT   SYS_REFCURSOR
    ) IS
    BEGIN
            EXECUTE IMMEDIATE 'alter session set nls_date_format=''dd-mm-yyyy''';
            OPEN br_out_rec FOR 
            SELECT * FROM DUAL;        
         CLOSE br_out_rec;
     END liorbybranch;
END gettorim;
/

Package body created.
SQL>

variable br_out_rec refcursor;
DECLARE
BEGIN
TABULA.gettorim.liorbybranch(:br_out_rec);
END;
/
print br_out_recSQL>   2    3    4    5
PL/SQL procedure successfully completed.

SQL>
ERROR:
ORA-24338: statement handle not executed

SP2-0625: Error printing variable "br_out_rec"

I suspect there is some issue with the cursor itself , because it all started when I got ORA-01001 Invalid Cursor

答案1

得分: 0

That's because you closed the cursor; don't do that.

SQL> CREATE OR REPLACE PROCEDURE liorbybranch (br_out_rec OUT SYS_REFCURSOR)
2 IS
3 BEGIN
4 EXECUTE IMMEDIATE 'alter session set nls_date_format=''dd-mm-yyyy''';

6 OPEN br_out_rec FOR SELECT * FROM DUAL;

8 -- CLOSE br_out_rec; --> here
9 END liorbybranch;
10 /

Procedure created.

SQL> var br_out_rec refcursor;
SQL> exec liorbybranch(:br_out_rec);

PL/SQL procedure successfully completed.

SQL> print br_out_rec

D

X

SQL>

英文:

That's because you closed the cursor; don't do that.

SQL> CREATE OR REPLACE PROCEDURE liorbybranch (br_out_rec OUT SYS_REFCURSOR)
  2  IS
  3  BEGIN
  4     EXECUTE IMMEDIATE 'alter session set nls_date_format=''dd-mm-yyyy''';
  5
  6     OPEN br_out_rec FOR SELECT * FROM DUAL;
  7
  8     -- CLOSE br_out_rec;           --> here
  9  END liorbybranch;
 10  /

Procedure created.

SQL> var br_out_rec refcursor;
SQL> exec liorbybranch(:br_out_rec);

PL/SQL procedure successfully completed.

SQL> print br_out_rec

D
-
X

SQL>

huangapple
  • 本文由 发表于 2023年5月10日 19:43:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76217980.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定