Solved

Differences between cursor and refcursor

Posted on 2003-11-24
3
1,246 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
3 Comments
 
LVL 15

Accepted Solution

by:
andrewst earned 250 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
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.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now