oracle where子句中的选定列别名[重复]

qyzbxkaa  于 2023-03-22  发布在  Oracle
关注(0)|答案(1)|浏览(129)

此问题在此处已有答案

Using an Alias in a WHERE clause(5个答案)
昨天关门了。
如何在where子句中放入别名列名(CO_NUMBER)。我尝试使用别名名称,但不起作用,我需要在CO_NUMBER列中放入整个条件提及吗?

Select  A_TBL.ID, A_TBL.EmpId,
        B_TBL.Tans, 
        DBMS_LOB.SubStr( TXT, 
            DBMS_LOB.InStr(TXT, '"', DBMS_LOB.InStr(TXT, '"CompanyNumber":"') + Length('"CompanyNumber":"'), 1  ) - (DBMS_LOB.InStr(TXT, '"CompanyNumber":"') + Length('"CompanyNumber":"')),
            DBMS_LOB.InStr(TXT, '"CompanyNumber":"') + Length('"CompanyNumber":"')
          ) "COMPANY NUMBER"
From
    A_TBL join B_Tbl on A_TBL.id = B_TBL.id  
Where "COMPANY NUMBER" = 'A1'
jljoyd4f

jljoyd4f1#

要在WHERE子句中使用 named expression,您需要在子查询中正式生成它。例如:

select *
from ( -- subquery starts here
  select
    ID,
    EmpId,
    DBMS_LOB.SubStr( TXT, 
      DBMS_LOB.InStr(TXT, '"', 
      DBMS_LOB.InStr(TXT, '"CompanyNumber":"') + Length('"CompanyNumber":"'), 
      1  ) - (DBMS_LOB.InStr(TXT, '"CompanyNumber":"') 
      + Length('"CompanyNumber":"')),
      DBMS_LOB.InStr(TXT, '"CompanyNumber":"') +
      Length('"CompanyNumber":"')
    ) as CO_NUMBER
  from A_TBL
) x -- subquery ends here
where CO_NUMBER = 'A1'

编辑--添加带有额外字符的别名。
您可以用双引号将别名括起来,以便在别名有效的任何地方使用它。例如:

select *
from (
  select a, b, a + b as "A and B" from t
) x
where "A and B" > 6

相关问题