Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Case Statement Help Needed

962004Sep 13 2012 — edited Sep 13 2012
I 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
This post has been answered by Sven W. on Sep 13 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 11 2012
Added on Sep 13 2012
6 comments
1,855 views