GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Oracle
Next Question 
 Oracle  |  Question 1 of 69    Print  
What is the difference between REF Cursor & Normal Cursor?

  
Total Answers and Comments: 11 Last Update: June 09, 2008     Asked by: SaratKumar 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
  Sorting Options  
  Page 1 of 2   « First    1    2    >     Last »  
October 21, 2005 07:31:33   #1  
prathima        

RE: What is the difference between REF Cursor & Normal...

Ref Cursor:

ref cursor is a data structure which points to an object which in turn points to the memory location.

ex:

create or replace procedure test()

as

begin

type ref_cursor is ref cursor;

open ref_cursor as

select * from table_name;

end;

There are 2 types in this.

1.strong ref cursor:

This has a return type defined.

2. weak ref cursor.

this doesnt have a return type

normal cursor:

Nothing but the named memory location.

it has 2 types

1. explicit cursor

Need to be defined  whenever required.

2.Implicit cursor

need not defined and used by oracle implicitly in DML operation.


 
Is this answer useful? Yes | No
October 24, 2005 01:35:13   #2  
Mehtab        

can anybody tell in detail What is the difference between REF Cursor & Normal...
whats the diffrance between ref cursor and normal cursor in detail
 
Is this answer useful? Yes | No
November 29, 2005 03:41:15   #3  
suresh        

What is the difference between REF Cursor & No...

Generally ref cursor used for passing cursor parameter and also dynamically building the query.

Normal cursor are static cursors and also we can't able to pass like paramater


 
Is this answer useful? Yes | No
January 03, 2006 10:02:42   #4  
Sourav        

RE: What is the difference between REF Cursor & No...

Hi Prathima,

Could you please explain in detail the difference with EXAMPLES ?

Has Refcursor anything do with formatting the queries in SQL*Plus ?

Why will i use REFCURSOR instead of CURSOR(Ordinary) ????Is it only for MEMORY AREA ???

Thanks,

Sourav


 
Is this answer useful? Yes | No
May 17, 2006 06:27:35   #5  
aseemnaithani Member Since: February 2006   Contribution: 10    

RE: What is the difference between REF Cursor & No...

hi,

the normal cursor is a static cursor i.e we in the normal cursor the query is only assigned at the design time and it can't be change at the run time.

for e.g

create or replace procedure sp_demo_cursor (squery varchar2)is

cursor c1 is squery;

begin

for v1 in c1 loop

---

--

end loop;

end;

assume that there is a requirement that we need to send the query as the parameter of the procedure, in the above case we can't do that. it will give an error.

but the same can be achieved by using the ref cursor.

in other words we can say that ref cursor supports the dynamic change in the cursor.

it also help in memory allocation

hope that above example is helpful and have cleared your doubts.

thanks.


 
Is this answer useful? Yes | No
April 19, 2007 09:45:22   #6  
Ram Prasad        

RE: What is the difference between REF Cursor & No...
In case of an normal explict cursor, the SQL query has to be defined at the time of declaring the cursor itself.  In case of REF Cursor, the cursor declartion is not associated with any SQL query, it is associated with a query at a later stage this brings in a lot of flexibility as different SQL queries can be associated with the cursor (one at a time, offcourse) programatically.  REF Cursors also provide the feature of passing parameters.  Though there is something dynamic with REF Cursor when compared to a normal explicit cursor, it is not a truly perfect dynamic cursor.  Truly perfect dynamic cursors are the one constructed using DBMS_SQL package.
 
Is this answer useful? Yes | No
June 29, 2007 07:38:53   #7  
nambiaruran        

RE: What is the difference between REF Cursor & No...
Ref cursor is a cursor variable that point to any cursor, mainly used for returning the cursor output.
 
Is this answer useful? Yes | No
July 04, 2007 06:09:14   #8  
anil.lohan        

RE: What is the difference between REF Cursor & No...

A REF CURSOR is basically a data type.  A variable created based on such a data type is generally called a cursor variable.  A cursor variable can be associated with different queries at run-time.  The primary advantage of using cursor variables is their capability to pass result sets between sub programs (like stored procedures, functions, packages etc.).

Example :-

declare
  type r_cursor is REF CURSOR;
  c_emp r_cursor;
  type rec_emp is record
  (
    name  varchar2(20),
    sal   number(6)
  );
  er rec_emp;
  procedure PrintEmployeeDetails is
  begin
    loop
      fetch c_emp into er;
      exit when c_emp%notfound;
      dbms_output.put_line(er.name || ' - ' || er.sal);
    end loop;
  end;
begin
  for i in (select deptno,dname from dept)
  loop
    open c_emp for select ename,sal from emp where deptno = i.deptno;
    dbms_output.put_line(i.dname);
    dbms_output.put_line('--------------');
    PrintEmployeeDetails;
    close c_emp; 
  end loop;
end;

In the above program, the sub-routine is named "PrintEmployeeDetails."  You can observe that I am executing (or calling) the sub-routine from within the loop as follows:

  for i in (select deptno,dname from dept)
  loop
      .
      .
      PrintEmployeeDetails;
      .
      .
  end loop;



 
Is this answer useful? Yes | No
August 31, 2007 16:58:35   #9  
ilangovan        

RE: What is the difference between REF Cursor & No...

Another difference is as below.

When we need of getting a resultset from applications like java,.net we used to call procedure which inturn will return ref cursor as out  parameter with resultset.


 
Is this answer useful? Yes | No
June 08, 2008 12:01:44   #10  
SATYANARAYAN KANUNGO Member Since: February 2008   Contribution: 1    

RE: What is the difference between REF Cursor & Normal Cursor?
 A REF CURSOR is basically a data type.

 
Is this answer useful? Yes | No
  Page 1 of 2   « First    1    2    >     Last »  


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape