Solved

Need to calculate age in PLSQL using sysdate

Posted on 2003-11-30
4
2,832 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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

867 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

22 Experts available now in Live!

Get 1:1 Help Now