Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PL/SQL: How can I calculate the AGE knowing a column called Birth_Date?

Tags:

plsql

I have a table consisting of one column (BIRTH_DATE). How could I use sysdate to subtract from all the rows of my BIRTH_DATE and GROUP BY them together?

to be more clear:

Here is what I have fetched, now I would like to add an AGE Column to the below Table for all rows

ID     Birth_Date
___    ___________
1       02-JAN-63
2       23-OCT-31
3       30-DEC-35
4       06-MAY-83

Thanks in advance!

like image 531
user1683987 Avatar asked Jan 23 '26 18:01

user1683987


1 Answers

To get a person's age according to the usual criterion (i.e. according to the number of calendar years that have passed since their birth), taking into account leap years, you can use the MONTHS_BETWEEN operator:

SELECT id, MONTHS_BETWEEN(sysdate, birth_date) / 12 age FROM my_table;
like image 132
Jeffrey Kemp Avatar answered Jan 26 '26 06:01

Jeffrey Kemp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!