Oracle:在同一Select语句中使用伪列值 [英] Oracle: Using Pseudo column value in the same Select statement

查看:206
本文介绍了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
)

这篇关于Oracle:在同一Select语句中使用伪列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆