?
Solved

Differences between cursor and refcursor

Posted on 2003-11-24
3
Medium Priority
?
1,255 Views
Last Modified: 2008-02-26
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.
0
Comment
Question by:king0452
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 15

Accepted Solution

by:
andrewst earned 1000 total points
ID: 9809814
A cursor is constant: it is linked to one defined query like this:

declare
  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;
begin
  if param1 = 1 then
    open rc for select * from emp;
  else
    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;
begin
  open rc for p_sql;
  ...
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question