Oracle: using a Pseudo column value in a single Select statement

I have a script in oracle where I need to be able to reuse the value of a pseudo column that was calculated earlier in the same select clause, for example:

select 'output1' process, process || '-Output2' from Table1 

I do not want to repeat the logic of the first columns again in the second column for maintenance purposes, currently this is done as

 select 'output1' process, 'output1' || '-Output2' name from Table1 

since I have 4 such columns that depend on the previous output of the column, repetition will be a maintenance nightmare

Edit: I included the table name and deleted the double, so no assumptions that this is not a complicated process, my actual statement has 2 to 3 joins in different tables

+4
source share
3 answers

You can calculate the value in a subquery:

 select calculated_output process, calculated_output || '-Output2' name from ( select 'output1' calculated_output from dual ) 
+9
source

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

 with tmp as ( select 'output' process from dual ) select process, process || '-Output2' from tmp; 
+9
source

very similar to the previous poster, but I prefer the method that I will show below, it is more readable, and therefore more convenient, in my opinion,

 select val1 || val2 || val3 as val4, val1 from ( select 'output1' as val1, '-output2' as val2, '-output3' as val3 from dual ) 
+2
source

All Articles