RE: What is the difference between REF Cursor & No...
hi,
the normal cursor is a static cursor i.e we in the normal cursor the query is only assigned at the design time and it can't be change at the run time.
for e.g
create or replace procedure sp_demo_cursor (squery varchar2)is
cursor c1 is squery;
begin
for v1 in c1 loop
---
--
end loop;
end;
assume that there is a requirement that we need to send the query as the parameter of the procedure, in the above case we can't do that. it will give an error.
but the same can be achieved by using the ref cursor.
in other words we can say that ref cursor supports the dynamic change in the cursor.
it also help in memory allocation
hope that above example is helpful and have cleared your doubts.
RE: What is the difference between REF Cursor & No...
In case of an normal explict cursor, the SQL query has to be defined at the time of declaring the cursor itself. In case of REF Cursor, the cursor declartion is not associated with any SQL query, it is associated with a query at a later stage this brings in a lot of flexibility as different SQL queries can be associated with the cursor (one at a time, offcourse) programatically. REF Cursors also provide the feature of passing parameters. Though there is something dynamic with REF Cursor when compared to a normal explicit cursor, it is not a truly perfect dynamic cursor. Truly perfect dynamic cursors are the one constructed using DBMS_SQL package.
RE: What is the difference between REF Cursor & No...
A REF CURSOR is basically a data type. A variable created based on such a data type is generally called a cursor variable. A cursor variable can be associated with different queries at run-time. The primary advantage of using cursor variables is their capability to pass result sets between sub programs (like stored procedures, functions, packages etc.).
Example :-
declare type r_cursor is REF CURSOR; c_emp r_cursor; type rec_emp is record ( name varchar2(20), sal number(6) ); er rec_emp; procedure PrintEmployeeDetails is begin loop fetch c_emp into er; exit when c_emp%notfound; dbms_output.put_line(er.name || ' - ' || er.sal); end loop; end; begin for i in (select deptno,dname from dept) loop open c_emp for select ename,sal from emp where deptno = i.deptno; dbms_output.put_line(i.dname); dbms_output.put_line('--------------'); PrintEmployeeDetails; close c_emp; end loop; end;
In the above program, the sub-routine is named "PrintEmployeeDetails." You can observe that I am executing (or calling) the sub-routine from within the loop as follows:
for i in (select deptno,dname from dept) loop . . PrintEmployeeDetails; . . end loop;
RE: What is the difference between REF Cursor & No...
Another difference is as below.
When we need of getting a resultset from applications like java,.net we used to call procedure which inturn will return ref cursor as out parameter with resultset.