Oracle:在同一Select语句中使用伪列值
我在oracle中有一个场景,我需要能够重用先前在同一select语句中计算出的伪列的值,例如:
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:
select 'output1' process, process || '-Output2' from Table1
出于维护目的,我不想在第二列中再次重复第一列逻辑,
I don't want to the repeat the first columns logic again in the second column for maintenance purposes, currently it is done as
select 'output1' process, 'output1' || '-Output2' name from Table1
由于我有4个这样的列,具体取决于上一列的输出,因此重复将是维护的噩梦
since i have 4 such columns which depend on the previous column output, repeating would be a maintenance nightmare
我添加了表名并删除了对偶表,因此没有任何关于这不是一个复杂过程的假设,我的实际语句在不同的表上确实有2到3个连接
i included table name and removed dual, so that no assumptions are made about that this is not a complex process, my actual statement does have 2 to 3 joins on different tables
您可以在子查询中计算值:
You could calculate the value in a sub-query:
select calculated_output process, calculated_output || '-Output2' name from
(
select 'output1' calculated_output from dual
)