Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

return clause in cursor

This is a discussion on return clause in cursor within the Oracle forums, part of the Databases category; What does a cursor returns? will it returns something just like procedures? then, for what the return clause is used in declare cursor statement?...

Go Back   Geeks Talk > Databases > Oracle
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read

Oracle Oracle 9i & Oracle 10g Knowledge Base Learn and Share Oracle Technology related articles, white papers, tutorials / study materials, example codes, FAQ's, Tips and Tricks.

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-11-2007
Expert Member
 
Join Date: Dec 2006
Location: Chennai
Posts: 210
Thanks: 2
Thanked 17 Times in 15 Posts
Barbie is on a distinguished road
return clause in cursor

What does a cursor returns?
will it returns something just like procedures?

then, for what the return clause is used in declare cursor statement?
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-12-2007
Expert Member
 
Join Date: Sep 2006
Location: India
Posts: 131
Thanks: 1
Thanked 21 Times in 20 Posts
Innila is on a distinguished road
Re: return clause in cursor

Quote:
Originally Posted by Barbie View Post
What does a cursor returns?
will it returns something just like procedures?

then, for what the return clause is used in declare cursor statement?
Cursor will return fetched record(s) for the statment which has been declared.
Barbie, can u give an example for ur doubt.
I wanted to understand ur problem clearly.

*** Innila ***

Last edited by Innila; 02-20-2007 at 04:13 AM.
Reply With Quote
  #3 (permalink)  
Old 01-17-2007
Expert Member
 
Join Date: Dec 2006
Location: Chennai
Posts: 210
Thanks: 2
Thanked 17 Times in 15 Posts
Barbie is on a distinguished road
Re: return clause in cursor

CURSOR company_cur (id_in IN NUMBER)
RETURN company%ROWTYPE IS
SELECT * FROM company;

What a declare cursor statement like this one will do?
For what that return clause?
what does it returns? and how?
Reply With Quote
  #4 (permalink)  
Old 01-17-2007
Expert Member
 
Join Date: Dec 2006
Location: India
Posts: 140
Thanks: 0
Thanked 7 Times in 5 Posts
nikhil_rattan is on a distinguished road
Re: return clause in cursor

Hi, the cursor return clause one of the most significant new features in pl/sql version 2 is the full support for packages and the resulting modularization of code that is now possible with that construct. Packages introduce an enhancement to the way you can declare a cursor: the return clause.when you group programs together into a package, you can make only the specification, or header information, of those programs available to developers. Although a developer can tell from the specification what the module is called and how to call it, he or she does not need to see any of the underlying code. As a result, you can create true black boxes behind which you can hide complex implementational details. With version 2 of pl/sql you can accomplish the same objective with cursors by using the cursor return clause. The return clause allows you to create a specification for a cursor which is separate from its body (the select statement). You may then place cursors in packages and hide the implementation details from developers. Consider the following cursor declaration with return clause: cursor caller_cur (id_in in number) return caller%rowtype is select * from caller where caller_id = id_in; the specification of the caller_cur cursor is: cursor caller_cur (id_in in number) return caller%rowtype while the body of the caller_cur cursor is: select * from caller where caller_id = id_in; everything up to but not including the is keyword is the specification, while everything following the is keyword is the body. You can include a return clause for any cursor you write in pl/sql version 2, but it is required only for cursors which are contained in a package specification. The return clause may be made up of any of the following datatype structures: · a record defined from a database table, using the %rowtype attribute · a record defined from a programmer-defined record here is an example of a cursor defined in a package. First, the package specification provides the name of the cursor and the return datatype (an entire row from the company table): package company is cursor company_cur (id_in number) return company%rowtype; end company; then the following package body repeats the cursor specification and adds the sql statement: package body company is cursor company_cur (id_in number) return company%rowtype is select * from company where company_id = id_in; end company; the number of expressions in the cursor's select list must match the number of columns in the record identified by table_name%rowtype or plsql_record%rowtype. The datatypes of the elements must also be compatible. If the second element in the select list is type number, then the second column in the return record cannot be type varchar2 or boolean. Why place cursors in a package? for the same reasons you would place a procedure or a function in a package: a package is a collection of logically related objects. By grouping the code into a package you make it easier for a developer to identify. Packaged cursors are essentially black boxes. This is advantageous to developers because they never have to code or even see the select statement. They only need to know what records the cursor returns, in what order it returns them, and which columns are in the column list. When cursor information is limited on this kind of "need to know" basis, it protects developers and the overall application from change. Suppose that a year from now the where clause of a query has to change. If a packaged cursor is not used, then each program that has a hardcoded or local cursor will have to be modified to meet the new specification. If, on the other hand, all developers simply access the same cursor, then changes will only need to be made to that packaged declaration of the cursor. The programs can then be recompiled to automatically support this change. I hope above information explain ur query and solve ur mind puzzle . Regards nikhil rattan
Reply With Quote
  #5 (permalink)  
Old 01-31-2007
Expert Member
 
Join Date: Sep 2006
Location: India
Posts: 131
Thanks: 1
Thanked 21 Times in 20 Posts
Innila is on a distinguished road
Re: return clause in cursor

Hi Barbie,

A cursor with a RETURN clause will have all columns of the underlying table (same structure as the underlying table) as the result set.

For Example,
CURSOR emp_cur RETURN employee%ROWTYPE
IS
SELECT * FROM employee
WHERE department_id = 10;

The RETURN clause can have 2 types of datatype structures,
1) A record defined from a database table, using the %ROWTYPE attribute &
2) A record defined from a programmer-defined record

*** Innila ***

Last edited by Innila; 02-20-2007 at 04:30 AM.
Reply With Quote
  #6 (permalink)  
Old 07-08-2009
Junior Member
 
Join Date: Jul 2009
Location: India
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
sandnaik is on a distinguished road
Re: return clause in cursor

Can u tell how to find the values returned by the cusror using return clause
in the form of query.

I mean how to query that cursor to find out what values that cursor as returned.
Reply With Quote
Reply

  Geeks Talk > Databases > Oracle

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
GROUP_BY and HAVING clause in SQL nancyphilips SQL 5 09-08-2008 11:39 PM
Return Value of Functions janelyn C and C++ 3 09-24-2007 01:09 AM
Can void be the return value of main Function joel C and C++ 3 09-10-2007 01:21 AM
What is the Return Value RajivPrasad ASP.NET 1 10-09-2006 03:17 PM
Presence of Clause nehalshah MainFrame 1 10-09-2006 03:01 PM


All times are GMT -4. The time now is 04:46 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2005 - 2010 GeekInterview.com. All Rights Reserved