Solved

Need to calculate age in PLSQL using sysdate

Posted on 2003-11-30
4
2,808 Views
Last Modified: 2012-05-04
Hello,
i am currently creating a member function in PLSQL and need to calculate the age of a person using the sysdate function. how can that be done? i am not sure how to split the sysdate to use only the year....

thanx!!
0
Comment
Question by:ZakdaMan
4 Comments
 
LVL 15

Accepted Solution

by:
andrewst earned 50 total points
ID: 9846366
Use MONTHS_BETWEEN to get number of months, divide by 12 to get years and then use FLOOR to remove digits after the decimal point:

SELECT FLOOR( MONTHS_BETWEEN( SYSDATE, date_of_birth ) / 12 )

To answer your second question, TRUNC(SYSDATE,'YYYY') returns the date TO_DATE('01-JAN-2003') (assuming current year is 2003).
0
 
LVL 7

Expert Comment

by:grim_toaster
ID: 9848710
Here's a link to a question I raised last week relating to date calculation, with some examples in the question of how you can calculate ages (but read the question as not all of them work, and I'm, still waiting to see if someone can give me an answer as to why!

http://www.experts-exchange.com/Databases/Oracle/Q_20808927.html
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to recover a database from a user managed backup

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now