Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Cursor variables, Stored Procedures & Pro C
I want to beable to call one stored procedure from a Proc C routine to
open a cursor and then call a second stored procedure to perform a fetch
from that cursor.
According to the Oracle documentation, if you defined & declare a cursor variable and then open the cursor variable, the pointer into the query work area should remain accessable from one scope to another. However it does not seem to do so. I receive a runtime error of ( ORA-01001: invalid_cursor) if I try and open a cursor in one pl/sql block and then fetch in another. Does anyone know why? Should it work this way?
Thanks in advance for your help!
pamela
Here's what I do in my code:
type my_cursor is REF CURSOR return my_rec;
procedure openmycursor(cur_variable IN OUT my_cursor, , , ); procedure fetchrowfrommycursor(cur_variable IN OUT my_cursor,
returnrec OUTmy_rec );
end my_package_name;
create or replace package body my_package_name as
procedure openmycursor (cur_variable IN OUT my_cursor, , ,) is begin open cur_variable for select ........; end openmycursor; procedure fetchrowfrommycursor(cur_variable IN OUT my_cursor, returnrec OUT my_rec) is begin fetch cur_variable into returnrec; end fetchrowfrommycursor;
2) My Pro C code
...
#include <oraca.h>
exec sql include sqlca;
exec sql whenever sqlerror do my_error_code();
int
main()
{
[connect to database with user ID ]
exec sql begin declare section;
sql_cursor cursor_variable;
typedef struct my_rec { }my_rec_type; my_rec_type return_rec;
exec sql allocate :cursor_variable;
exec sql execute
begin my_package_name.openmycursor(:cursor_variable, , , ); end;
[ more user code here ]
/* I receive a runtime error 'ORA-01001: invalid_cursor' on the first iteration of the loop */
/* Note: I can do many "exec sql fetch :cursor_variable into :returnrec;"
exit when :cursor_variable%notfound; end loop; end;
![]() |
![]() |