本文介绍了在同一选择中使用列别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在同一查询的其他地方使用列别名?在Oracle中有可能吗?

How can I use a column alias somewhere else in the same query? Is it possible in Oracle?

使用EMP_ID的示例:

Example using EMP_ID:

SELECT
    t1.DATE, t2.NAME, t1.ID,
    TO_NUMBER( SUBSTR( t1.NUMBER_ID, - 6)
      || TRIM( TO_CHAR( SUBSTR(EMP_ID, 3, 2), '00' ) ), '999999999999') AS CONTRACT,
    t2.ADDRESS,
    CASE WHEN SUBSTR(t2.COD_EMP, 0, 2) != 'PG' THEN 'PG00'
      || t2.COD_EMP ELSE t2.COD_EMP END AS EMP_ID
FROM
    TABLE_01 t1
    INNER JOIN TABLE_02 t2 .....

推荐答案

按照标准SQL:在任何特定SELECT子句中的所有列都是好像"计算的,它们都是并行计算的(允许某些实现正是这样做的.)

Per standard SQL: All columns in any particular SELECT clause are computed "as if" they're all being computed in parallel (to allow some implementation to do precisely that).

因此,不允许您依赖同一SELECT子句中定义的另一列,因为尚未计算其值.

As such, you're not allowed to depend on another column defined within the same SELECT clause since it's value has not yet been computed.

这篇关于在同一选择中使用列别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 01:36