Home » SQL & PL/SQL » SQL & PL/SQL » Fetching values from tables (Oracle)
Fetching values from tables [message #357729] Thu, 06 November 2008 06:56 Go to next message
Messages: 1
Registered: November 2008
Junior Member
I need to calculate age of the person who will complete 20 years of age whose birthday falls within the given date range. There is a field called birthdate and there are 2 more date fields (date1 and date2) as input parameters.

For Eg,
Birthdate : 10/08/1988
Date1 as input parametr : 10/01/2008
Date2 as input parametrs : 10/10/2008

I need to find:

1) the Age of the employee (ie. 20 should be displayed)
2) the date when the employee will complete 20 years ( the query should display 10/08/2008. Hard code value not allowed..need to dynamically calculate the value)

Any help will be appreciated.

Thanks in advance
Re: Fetching values from tables [message #357734 is a reply to message #357729] Thu, 06 November 2008 07:04 Go to previous messageGo to next message
Michel Cadot
Messages: 63956
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Post what you already tried but before read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code (See SQL Formatter) and align the columns in result.
Use the "Preview Message" button to verify.
Always post your Oracle version (4 decimals).

If you want a quick answer it is good to post a test case: create table and insert statements along with the result you want with these data.

Re: Fetching values from tables [message #357736 is a reply to message #357729] Thu, 06 November 2008 07:08 Go to previous message
Messages: 1832
Registered: November 2006
Senior Member
Have a look at MONTHS_BETWEEN and/or ADD_MONTHS functions. Keep in mind, that each year contains 12 months.
These functions are described in SQL Reference book, which is part of Oracle documentation, available e.g. online on http://tahiti.oracle.com/.
Previous Topic: format after concat number
Next Topic: Need a bit of help with function basics..
Goto Forum:

Current Time: Fri Oct 28 18:43:48 CDT 2016

Total time taken to generate the page: 0.29620 seconds