0

I need to verify a procedure that has an out cursor parameter. Specifically I need to see what is retrieving.

I try this:

declare
  type cursor_out is ref cursor;
  cur cursor_out; 
  fila activ_economica%rowtype;
  procedure test(algo out cursor_out) is
  begin
    open algo for select * from activ_economica;  
  end;
begin
  test(cur);
  for i in cur loop
    fila := i;
    dbms_output.put(fila.id_activ_economica ||' ' );
    dbms_output.put_line(fila.nom_activ_economica);
  end loop;
end;

The error is that "cur" has not being defined.

mjsr
  • 7,410
  • 18
  • 57
  • 83

1 Answers1

2

You cannot use cursor FOR loop with a ref cursor, you must do this:

declare
  type cursor_out is ref cursor;
  cur cursor_out; 
  fila activ_economica%rowtype;
  procedure test(algo out cursor_out) is
  begin
    open algo for select * from activ_economica;  
  end;
begin
  test(cur);
  loop
    fetch cur into fila;
    exit when cur%notfound;
    dbms_output.put(fila.id_activ_economica ||' ' );
    dbms_output.put_line(fila.nom_activ_economica);
  end loop;
  close cur;
end;

Note: there is no longer any need to define your own ref cursor type (unless you are on a very old version of Oracle). You can just use SYS_REFCURSOR instead:

declare
  cur sys_refcursor; 
  ...
Tony Andrews
  • 129,880
  • 21
  • 220
  • 259
  • excelent, i searched a lot and I could't find anything, you save me a day of work :D – mjsr Jun 13 '12 at 16:50