Can you use a reference cursor as an input parameter in a procedure with out declaring it explicitly?

Showing Answers 1 - 15 of 15 Answers

No, because an Explicit cursor is the only one we are going to create that only we can able to keep as a parameter, Implicit cursor is created by the oracle server only so we can't access it

  Was this answer useful?  Yes

Question it self is wrong.

In cursors there are two types.
1.Implicit cursors
2. Explicit cursors
       Explicit cursors can be defined as dynamic (Reference ) or static.
       Only reference cursors can be passed as parameter - static cursor can't.

  Was this answer useful?  Yes

Oh  sorry.

You can not declare . Here is the example
PROCEDURE test_ref (emp_cur IN my_refcursor) IS
emp_rec emp%ROWTYPE;
BEGIN
LOOP
FETCH emp_cur INTO emp_rec;
EXIT WHEN emp_cur%NOTFOUND;
dbms_output.put_line(emp_rec.ename ||' is a ' || emp_rec.job);
END LOOP;
END;

It will throw error
PLS-00201: identifier 'MY_REFCURSOR' must be declared

But you can pass it as sys_refcursor without getting any error.

CREATE OR REPLACE PROCEDURE test_ref (emp_cur IN sys_refcursor) IS
emp_rec emp%ROWTYPE;
BEGIN
LOOP
FETCH emp_cur INTO emp_rec;
EXIT WHEN emp_cur%NOTFOUND;
dbms_output.put_line(emp_rec.ename ||' is a ' || emp_rec.job);
END LOOP;
END;


  Was this answer useful?  Yes

gwilson5

  • Sep 4th, 2010
 

A cursor variable is a variable that points to or refernces an underlying cursor.  Unlike an explicit cursor, which names the PL/SQL work area for the result set, a cursor variable is a reference to that work area.  Explicit and implicit cursor are static in the they are tied to specific queries.  The cursor variable can be opened for any query, even for different queries within a single program execution.  You can pass a cursor variable as an argument in a call to a procedure or function.  You can use cursor variable in the parameter list of a program, you need to specify the mode of the parameter and the datatype (the REF CURSOR type).  To do this that cursor type must already be defined.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions