Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Normal cursor and ref cursor

User_JIAY3Mar 12 2015 — edited Mar 12 2015

Dear All,

I have created one normal cursor and another oneis ref cursor when i tried to run the below Noraml cursor and ref cursor datatype, we are getting same result set. Can you please tell me what is major diffrence both of them.

-- Normal Cursor

declare

cursor emp_c is select * from employees;

v_emp employees%rowtype;

begin

open emp_c;

loop

fetch emp_c into v_emp;

dbms_output.put_line(v_emp.employee_id||' '||v_emp.last_name||' '||v_emp.first_name);

exit

when emp_c%notfound;

end loop;

close emp_c;

end;

-- Using refcursor

declare

type cus is ref cursor;

cus1 cus;

emp_ro employees%rowtype;

begin

open cus1 for select * from employees;

loop

fetch cus1 into emp_ro;

dbms_output.put_line(emp_ro.employee_id||' '||emp_ro.last_name||' '||emp_ro.first_name);

exit

when cus1%notfound;

end loop;

close cus1;

end;

Thanks.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 9 2015
Added on Mar 12 2015
4 comments
332 views