Differences between cursor and refcursor

Please can anybody list out the differences between the Cursor and REFCursor.

Preparing for an interview.. Please list out any other related questions for interview purpose.

Thanks in advance.
Who is Participating?
andrewstConnect With a Mentor Commented:
A cursor is constant: it is linked to one defined query like this:

  cursor c1 (p_deptno in emp.deptno%TYPE) is select ename from emp where deptno = p_deptno;

A ref cursor is a cursor variable: the actual query can be changed at runtime like this:

procedure p( param1 in number ) is
  type rc is ref cursor;
  c1 rc;
  if param1 = 1 then
    open rc for select * from emp;
    open rc for select * from dept;
  end if;

Ref cursors are also used in dynamic SQL, where the query is defined as a text string, like this:

procedure p( p_sql in varchar2 ) is
  type rc is ref cursor;
  c1 rc;
  open rc for p_sql;
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.