SQL> SET ECHO ON
SQL> SET SERVEROUTPUT ON
SQL> DECLARE
2 age POSITIVE;
3
4 current_year NATURAL; --a year of 00 is valid.
5 current_month POSITIVE;
6 current_day POSITIVE;
7
8 birth_year NATURAL; --a year of 00 is valid.
9 birth_month POSITIVE;
10 birth_day POSITIVE;
11
12 BEGIN
13
14 current_year := 2121;
15 current_month := 12;
16 current_day := 13;
17
18
19 birth_year := 1234;
20 birth_month := 12;
21 birth_day := 12;
22
23 IF current_month > birth_month THEN
24 age := current_year - birth_year;
25 ELSIF (current_month = birth_month) and (current_day >= birth_day) THEN
26 age := current_year - birth_year;
27 ELSE
28 age := current_year - birth_year - 1;
29 END IF;
30 END;
31 /
SQL>