How to display the results of a ref cursor using SQL Developer

被刻印的时光 ゝ 提交于 2020-03-05 05:55:25

问题


I have a stored procedure with several cursors. They are defined as IN OUT parameters. I would like to display the result of the cursors using SQL Developer. This is an example of the stored procedure:

SET serveroutput on;
DECLARE
         p_input_stream       VARCHAR2(200);
        p_msg_code            NUMBER;
         p_msg_parms                         VARCHAR2(200);
         p_return_code                       NUMBER;
         p_trailer_cur                    sl_globals.curtype_weak;

 BEGIN
    /* Assign values to IN parameters */
    p_input_stream := '24954286Mnull|5155035|2|436|SCAN|47720|XTRA|0105||5155035||||N|~|\r';
    p_trailer_cur := null;

EXEC TRAILER_INFO(p_input_stream, 
        p_msg_code, p_msg_parms, p_return_code, 
        p_trailer_cur)

 /* Display OUT parameters */
    dbms_output.put_line('p_msg_code: ' || p_msg_code);
    dbms_output.put_line('p_msg_parms: ' || p_msg_parms);
    dbms_output.put_line('p_return_code: ' || p_return_code);

I have tried creating a refcursor variable and using it in place of p_trailer_cur like this

VARIABLE trailer_cur refcursor;
 EXEC TRAILER_INFO(p_input_stream, 
        p_msg_code, p_msg_parms, p_return_code, 
        :trailer_cur)
 print trailer_cur;

I get the error:

SP2-0552: Bind Varialbe "trailer_cur is not declared.

The variable is declared so I don't understand the error.


回答1:


Two ways SQL Developer supports this - the GUI and the Code.

The GUI

If you execute your stored procedure from the Code Editor, find the stored procedure in the tree, click on it, use the Execute button - we'll grab ALL of your output, and show it below in the output panels:

And your attempt, the Code:

If you're in the SQL Worksheet and you have your anonymous block, you can run it with F5, including your print command.

Like so -

create or replace function get_emps(dno in number) return sys_refcursor
    is
      return_value sys_refcursor;
    begin
      open return_value for
        select * from employees where department_id = dno;
      return return_value;
    end;
    /



 var rc refcursor
 exec :rc := get_emps(90)

 print rc



来源:https://stackoverflow.com/questions/54486796/how-to-display-the-results-of-a-ref-cursor-using-sql-developer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!