Oracle: Using Pseudo column value in the same Select statement

前端 未结 3 1842
囚心锁ツ
囚心锁ツ 2021-01-19 02:51

I have a scenario in oracle where i need to be able to reuse the value of a pseudo column which was calculated previously within the same select statement something like:

相关标签:
3条回答
  • 2021-01-19 03:44

    You can also use the subquery factoring syntax - i think it is more readable myself:

    with tmp as
    (  
      select 'output' process from dual
    )
    select 
      process, process || '-Output2' from tmp;
    
    0 讨论(0)
  • 2021-01-19 03:46

    You could calculate the value in a sub-query:

    select calculated_output process, calculated_output || '-Output2' name from
    (
        select 'output1' calculated_output from dual
    )
    
    0 讨论(0)
  • 2021-01-19 03:48

    very similar to the previous poster, but I prefer the method I show below, it is more readable, thusly more supportable, in my opinion

    select val1 || val2 || val3 as val4, val1 from (
       select 'output1' as val1, '-output2' as val2, '-output3' as val3 from dual
    )
    
    0 讨论(0)
提交回复
热议问题