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

o2gm4chl  于 2023-05-16  发布在  Oracle
关注(0)|答案(1)|浏览(89)
This is a minimal example:

我怀疑有一些问题与光标本身,因为这一切开始时,我得到了ORA-01001无效光标

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"

我怀疑有一些问题与光标本身,因为这一切开始时,我得到了ORA-01001无效光标

aemubtdh

aemubtdh1#

那是因为你关闭了光标;别这样。

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>

相关问题