ORA-24374: define not done before fetch or execute and fetch [message #410556] |
Sun, 28 June 2009 15:37 |
oracle123
Messages: 56 Registered: March 2009
|
Member |
|
|
Hi,
This is the first time I am working with ref cursors. My code looks like as follows:
create or replace procedure test(p_deptno IN number,
salary OUT number,
count OUT number)is
p_cursor sys_refcursor;
begin
open p_cursor FOR
select *
from emp
where deptno = p_deptno;
-- procedure to calculate total salary
total_dept_salary(p_cursor, salary);
-- procedure to calculate total head count in the department
total_dept_count(p_cursor, cnt);
end test;
The above procedure compiles successfully but I am getting the following error message when I test it:
ORA-24374: define not done before fetch or execute and fetch
The above error points to the line "total_dept_count(p_cursor, cnt); "
So, I tried to open the cursor once again before that statement as shown below and everything works fine.
create or replace procedure test(p_deptno IN number,
salary OUT number,
count OUT number)is
p_cursor sys_refcursor;
begin
open p_cursor FOR
select *
from emp
where deptno = p_deptno;
-- procedure to calculate total salary
total_dept_salary(p_cursor, salary);
open p_cursor FOR
select *
from emp
where deptno = p_deptno;
-- procedure to calculate total head count in the department
total_dept_count(p_cursor, cnt);
end test;
So my question is: Do I need to open the cursor every time I pass it into a new program unit or else am I missing something?
Thanks for the help in advance.
- Scott.
|
|
|
|
|
|
|
Re: ORA-24374: define not done before fetch or execute and fetch [message #410569 is a reply to message #410556] |
Mon, 29 June 2009 00:46 |
oracle123
Messages: 56 Registered: March 2009
|
Member |
|
|
@ Michel,
Quote: | Yes you have as the previous call fetched the rows from the previous cursor.
|
I thought when we use the following statement, it just identifies the active set from the database and does not fetch any data.
open p_cursor FOR
select *
from emp
where deptno = p_deptno;
So is there any other way to open the ref cursor just once at the starting of the code, and pass it as a parameter to different procedures?
Thanks for all your time.
- Scott.
|
|
|
|
|