Case Statement Help Needed
962004Sep 13 2012 — edited Sep 13 2012I am very new to writing PL/SQL statements. Here is the problem I would like help with. I am using "Oracle SQL Developer". I would like to take the age of an individual and make a derived column showing the age range they are in. My information is only coming from one table. Here is the code that I have written so far and the error message I receive:
SELECT DPSID,
LAST_NAME,
FIRST_NAME,
DOB,
trunc (MONTHS_BETWEEN (SYSDATE, e.dob) / 12) AS "Age"
CASE
WHEN trunc (MONTHS_BETWEEN (SYSDATE, e.dob) / 12) <= 21 THEN "18-21"
WHEN trunc (MONTHS_BETWEEN (SYSDATE, e.dob) / 12) BETWEEN 22 AND 30 THEN "22-30"
WHEN trunc (MONTHS_BETWEEN (SYSDATE, e.dob) / 12) BETWEEN 31 AND 40 THEN "31-40"
WHEN trunc (MONTHS_BETWEEN (SYSDATE, e.dob) / 12) BETWEEN 41 AND 50 THEN "41-50"
WHEN trunc (MONTHS_BETWEEN (SYSDATE, e.dob) / 12) BETWEEN 51 AND 60 THEN "51-60"
ELSE "60+"
END
AS "Age Bracket"
FROM ODS_OWNER.EMPLOYEES e;
ORA-00923: FROM keyword not found where expected
00923. 00000 - "FROM keyword not found where expected"
I would like to know how to get the "Age Bracket" column to appear when I run the query.
Thank you