Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > Oracle
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 12th, 2007, 04:26 AM
Authorized User
 
Join Date: Jan 2007
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
 
Old April 16th, 2007, 12:05 AM
Friend of Wrox
 
Join Date: May 2005
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.
 
Old April 16th, 2007, 12:37 PM
Authorized User
 
Join Date: Jan 2007
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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.