PL/SQL Age Calculation Function
Ok ... a lot of people may already know this method for determining a person's age, but it is useful. In fact, I used it today. If you work in a business where you are frequently asked to generate reports or find data with an age range as a search criteria, or as an end result, then you need this little bit of code/SQL in your bag of tricks.
CREATE OR REPLACE FUNCTION getAge(p_dob DATE, p_base_date DATE := SYSDATE) RETURN NUMBER
IS
v_age NUMBER(3) := 0;
BEGIN
v_age := TRUNC(MONTHS_BETWEEN(p_base_date,p_dob)/12);
RETURN v_age;
END;
10:39:45 PM
|