Gloria Santin
Gloria Santin

Reputation: 2136

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

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.

Upvotes: 2

Views: 10800

Answers (1)

thatjeffsmith
thatjeffsmith

Reputation: 22412

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:

enter image description here

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

enter image description here

Upvotes: 7

Related Questions