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.

function

This is a discussion on function within the Oracle forums, part of the Databases category; Can function return more values if yes how can it possible...

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 12-11-2007
Junior Member
 
Join Date: Dec 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
goutham_konduru is on a distinguished road
function

Can function return more values if yes how can it possible
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-11-2007
Expert Member
 
Join Date: Apr 2007
Location: Bangalore
Posts: 517
Thanks: 30
Thanked 63 Times in 61 Posts
susarlasireesha will become famous soon enough
Re: function

Functions (in any language, not just pl/sql) return one value. That may be restrictive, it's one more than procedures return. So what if you want to return a date and a numeric code that tells how accurate the date is? what if you want to look up an address, including city, state and zip code? solutions fall into three broad categories:
1. return a composite object
2.use out or in out arguments
3.don't return it: store it
each of the three approaches is useful in different circumstances. You might want to use all three approaches at the same time.

1. Return a composite object we're used to seeing functions that return simple, built-in types, like date. But dates aren't really simple, are they? an oracle date contains a date (in the non-oracle sense) and a time, and these, in turn, are compounds of year, month, minutes, etc. So the first, obvious trick you can use is to return a single large object (like a long varchar2) that you can parse after you have it. (don't laugh: a comma-separated list of values might be just the thing you need.) a function can also return an xmltype, a user-defined type, a pl/sql table, a cursor, or any kind of data structure you can have in pl/sql.

2. Use out or in out arguments
function emp_addr ( out_street out varchar2, out_city out varchar2, out_state out varchar2, out_zip_cd out varchar2, emp_id in number, max_len in number default 100 ) return boolean
the example above "returns" a single true-false value, but it sets four varchar2 variables along the way. You can (in fact, must) assign values to these variables in the body of the function. You can not read them. (declare the arguments as in out if you want to do both.) when you call the function, you must supply variables (not literals) for these arguments, and the variables have to be able to contain whatever the function tries to put in them. That's the purpose of the max_len argument in the example: i can call the function with tiny little strings, like this:
declare street_addr varchar2 (20); city_name varchar2 (20); ...
begin
... If emp_addr (street_addr, city_name, state_abbr, zip_cd, current_id, 20)
then
...
without risking a run-time error (only loss of data) as long as my function does something like: out_street := substr (emp_addr, 1, max_len);
remember to think objectively! the out (or in out) arguments can be xmltypes, user-defined types, etc.

3. Don't return it: store it ,store values in ordinary tables you can return hundreds of values at once. Temporary tables each session can have its own copy of the table
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
What is the use of abs function Geek_Guest QTP 1 07-23-2007 07:29 AM
throwexception from function to function JobHelper VB.NET 1 06-25-2007 07:24 AM
pl/sql function gujjar Oracle Certification 3 02-22-2007 10:47 AM
TSL Function sutnarcha WinRunner 1 12-20-2006 05:40 AM
Function in PHP sripri PHP 1 07-20-2006 12:13 PM


All times are GMT -4. The time now is 05:41 PM.


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