Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > Oracle
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Oracle General Oracle database discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Oracle section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 12th, 2007, 04:26 AM
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 46
Thanks: 2
Thanked 1 Time in 1 Post
Default PL/SQL Function returning age


 CREATE OR REPLACE FUNCTION FINDAGE(
 DT IN date)
 RETURN NUMBER IS
 AGE NUMBER;
 BEGIN
 AGE:= MONTHS_BETWEEN(SYSDATE,'DT');
 RETURN AGE;
 END;

What is really wrong with the above function?


MAXOOD!

Life is an endless journey towards perfection
__________________
MAXOOD!

Life is an endless journey towards perfection
  #2 (permalink)  
Old April 16th, 2007, 12:05 AM
Friend of Wrox
Points: 793, Level: 10
Points: 793, Level: 10 Points: 793, Level: 10 Points: 793, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2005
Location: OKC, OK, USA.
Posts: 227
Thanks: 1
Thanked 7 Times in 7 Posts
Default

code_lover:

There are several things I see that are not clear:
  1) The date parameter is not clear as to what "date" value are u passing to the function;
  2) To Compute someones age is: Year of Current Date - Year of DOB (Date of Birth). The months and day are used to indicate if they have had a birthday in the current year.;
  3) Even if you generated a number of months, you should divide that number by 12, converting your answer to years.

Hope this helps.

========================
Disclaimer: The above comments are solely the opinion of one person and not to be construed as a directive or an incentive to commit fraudulent acts.
  #3 (permalink)  
Old April 16th, 2007, 12:37 PM
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 46
Thanks: 2
Thanked 1 Time in 1 Post
Default

Thankyou very much for your feedback.Please go through the code below and let me know if i can improve it further.

CREATE OR REPLACE FUNCTION FINDAGE(
 DOB IN DATE)
 RETURN NUMBER
 IS
 YRS NUMBER;
 BEGIN
 YRS:= ROUND((SYSDATE - DOB)/365);
 RETURN YRS;
 END;

Wonder how can i add exception to it if the user enters wrong information like:
select findage(fgddf) from dual;
instead of
select findage('27-MAY-76') from dual;

MAXOOD!

Life is an endless journey towards perfection
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error while compiling PL/SQL function in 10g aagarwal123 Oracle 0 August 18th, 2007 01:20 AM
age function keyvanjan ASP.NET 1.0 and 1.1 Basics 2 August 30th, 2006 08:46 AM
Function not returning value civa Access 5 January 17th, 2006 03:44 AM
Age Old ODBC Sql Server Driver Timeout busher Classic ASP Databases 5 December 7th, 2005 12:10 PM
Function not returning anything... goatboy Beginning PHP 2 December 1st, 2003 12:34 PM



All times are GMT -4. The time now is 04:48 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.