Skip to content
Advertisement

Can I declare and use variables “inline” in Oracle SQL?

can I do something like this pseudo code and use variables inline within the select? I know that in this case variables are not needed, I have a more complex use case in mind.

select 
t.foo,
t.bar,

var var1 = 100 + t.foo + t.bar;
(return var1) as result

from table t
where 1=1 and ...

cheers

Advertisement

Answer

No, Oracle does not support your syntax:

select t.foo,
       t.bar,
       var var1 = 100 + t.foo + t.bar;
       (return var1) as result
from   table t
where  1=1
and    ...

The full syntax for the SELECT statement is documented here and that syntax is not included. Particularly:

SELECT syntax:

SELECT syntax

select_list syntax:

select_list syntax

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement