Skip to Main Content

SQL & PL/SQL

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!

Using field calculated in one case statement in another case statement.

User_8O42CSep 29 2017 — edited Oct 1 2017

I've copied a query from Teradata to use in Oracle.  Works fine in Teradata, but give error in Oracle 12c

ORA-00904: "my_years": invalid identifier

Is there a work-around?

Case

     when years = 1 then 'red'

     when years =2 then 'blue'

     when years = 3 then 'green'

end as my_years,

case

     when my_years between 1 and 5 then '01-05 years'

     when my_years between 6 and 10 then '06-10 years'

     when my_years  between  11 and 15 then '11-15 years'

end as year_bands

Want to see

my_years          Year_band

red                    01-05 years

blue                  06-10 years

green                11-15 years

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 29 2017
Added on Sep 29 2017
6 comments
1,746 views