What is difference between a Cursor declared in a procedure and Cursor declared in a package specification ?

 A  cursor declared in a package specification is global and can be accessed by other procedures or procedures in a package.A  cursor declared in a procedure is local to the procedure that can not be accessed by other procedures.

Showing Answers 1 - 7 of 7 Answers

The scope of A cursor declared in a procedure is limited to that procedure only.

The Scope of cursor declared in a package specification is global .

Example:

create or replace package curpack is

cursor c1 is select * from emp;

end curpack;

This will create a package Now You can use this cursor any where. Like:

set serveroutput on

begin

for r1 in curpack.c1 loop

dbms_output.put_line(r1.empno||'  '||r1.ename);

end loop;

end;

this will dispaly all empno and enames.

It will be better to use ref cursor in packages

  Was this answer useful?  Yes

divyesh

  • Oct 13th, 2007
 

Ref cursors are used when you want cursor to hold any no. of columns in the row.

If you are not sure about row type at complile time you use ref cursors.


Sys_ref_cursors used when you want cursors to be passed from one procedures to another procedures or functions.

  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