Difference Between Cursor And Ref Cursor
In this post I am trying to detail out the differences between Cursor and Ref Cursors. I am sure, this question has been asked in many interviews to many of us and it also has its own technical weightage. Lets first check the basic example of Cursor and Ref Cursors. In this post Cursor means PL/SQL Cursors only.
Example of Cursor:
declare cursor c1 is select ename, sal from scott.emp; begin for c in c1 loop dbms_output.put_line('Ename: ' || c.ename || ', Salary: ' || c.sal); end loop; end; /
Example of Ref Cursor
declare c1 SYS_REFCURSOR; ename varchar2(10); sal number; begin open c1 for select ename, sal from scott.emp; LOOP FETCH c1 into ename, sal; EXIT WHEN c1%NOTFOUND; dbms_output.put_line('Ename: ' || ename || ', Salary: ' || sal); END LOOP; close c1; end; /