Use Column Alias In Select Statement Calculation O

2019-07-04 05:03发布

问题:

Is it possible to do something like select 1 as foo, foo+1 from dual

This returns ERROR at line 1: ORA-00904: "FOO": invalid identifier

I have a lengthy calculation that composes a column and I would like to be able to easily use that value for calculation in a difference column

回答1:

You can't use an alias directly. One way is to use a derived table:

SELECT foo, foo+1
FROM (SELECT 1 AS foo FROM dual) AS T