Oracle- 为啥在组合列中显示此错误“ORA-00904: "OUTLET_STATUS": invalid identifier"?

Posted

技术标签:

【中文标题】Oracle- 为啥在组合列中显示此错误“ORA-00904: "OUTLET_STATUS": invalid identifier"?【英文标题】:Oracle- Why show this error " ORA-00904: "OUTLET_STATUS": invalid identifier " in combined column?Oracle- 为什么在组合列中显示此错误“ORA-00904: "OUTLET_STATUS": invalid identifier"? 【发布时间】:2017-02-12 05:32:35 【问题描述】:

我想在 oracle 中将两列合并为一列。我已经按照这个链接: this . 查询是:

SELECT T6.ITEM_GROUP_NAME,T7.ZONE_NAME,T5.SR_NAME, T5.SR_ID, T5.MOBILE_NO ,T3.ROUTE_NAME ,T1.OUTLET_NAME, T1.OUTLET_ADDRESS, T1.PROPRITOR_NAME, T1.MOBILE_NUMBER , T2.STATUS || T8.REASON as OUTLET_STATUS,
                    SUM(((T2.ITEM_CTN*T4.FACTOR)+ T2.ITEM_QTY )*T2.OUT_PRICE )AS AMOUNT 
                    FROM T_OUTLET T1 , T_ORDER_DETAIL T2, T_ROUTE T3 , T_ITEM T4 , T_SR_INFO T5 , T_ITEM_GROUP T6 ,T_ZONE T7 , T_NON_PRODUCTIVE_SALES T8
                    WHERE T6.ITEM_GROUP_ID='000200000' and T7.ZONE_ID='Z002' and T5.SR_ID= '174369' and T2.OUTLET_ID=T1.OUTLET_ID AND T3.ROUTE_ID = T2.ROUTE_ID AND T2.STATUS='Y' and T2.ENTRY_DATE= TO_DATE( '11/02/2017','dd/mm/yyyy') and T2.ITEM_ID=T4.ITEM_ID and T8.ENTRY_DATE= TO_DATE( '11/02/2017','dd/mm/yyyy') and T8.SR_ID = '174369' and T2.OUTLET_ID= T8.OUTLET_ID
                    GROUP BY T6.ITEM_GROUP_NAME,T7.ZONE_NAME,T5.SR_NAME, T5.SR_ID, T5.MOBILE_NO ,T2.ENTRY_DATE , T2.OUTLET_ID,T3.ROUTE_NAME ,T1.OUTLET_NAME, T1.OUTLET_ADDRESS, T1.PROPRITOR_NAME, T1.MOBILE_NUMBER , OUTLET_STATUS
                    ORDER BY T1.OUTLET_NAME

但是当我这样做时,它会显示错误:

ORA-00904:“OUTLET_STATUS”:标识符无效

问题出在哪里?

【问题讨论】:

【参考方案1】:

group by 的评估发生在select 之前,因此group by 不知道名为OUTLET_STATUS 的列。

group by 中的OUTLET_STATUS 更改为T2.STATUS || T8.REASON

select
. . .
group by T6.ITEM_GROUP_NAME,
    T7.ZONE_NAME,
    T5.SR_NAME,
    T5.SR_ID,
    T5.MOBILE_NO,
    T2.ENTRY_DATE,
    T2.OUTLET_ID,
    T3.ROUTE_NAME,
    T1.OUTLET_NAME,
    T1.OUTLET_ADDRESS,
    T1.PROPRITOR_NAME,
    T1.MOBILE_NUMBER,
    T2.status || T8.REASON  --here
order by T1.OUTLET_NAME

因此,您的查询变为:

select T6.ITEM_GROUP_NAME,
    T7.ZONE_NAME,
    T5.SR_NAME,
    T5.SR_ID,
    T5.MOBILE_NO,
    T3.ROUTE_NAME,
    T1.OUTLET_NAME,
    T1.OUTLET_ADDRESS,
    T1.PROPRITOR_NAME,
    T1.MOBILE_NUMBER,
    T2.status || T8.REASON as OUTLET_STATUS,
    SUM(((T2.ITEM_CTN * T4.FACTOR) + T2.ITEM_QTY) * T2.OUT_PRICE) as AMOUNT
from T_OUTLET T1,
    T_ORDER_DETAIL T2,
    T_ROUTE T3,
    T_ITEM T4,
    T_SR_INFO T5,
    T_ITEM_GROUP T6,
    T_ZONE T7,
    T_NON_PRODUCTIVE_SALES T8
where T6.ITEM_GROUP_ID = '000200000'
    and T7.ZONE_ID = 'Z002'
    and T5.SR_ID = '174369'
    and T2.OUTLET_ID = T1.OUTLET_ID
    and T3.ROUTE_ID = T2.ROUTE_ID
    and T2.status = 'Y'
    and T2.ENTRY_DATE = TO_DATE('11/02/2017', 'dd/mm/yyyy')
    and T2.ITEM_ID = T4.ITEM_ID
    and T8.ENTRY_DATE = TO_DATE('11/02/2017', 'dd/mm/yyyy')
    and T8.SR_ID = '174369'
    and T2.OUTLET_ID = T8.OUTLET_ID
group by T6.ITEM_GROUP_NAME,
    T7.ZONE_NAME,
    T5.SR_NAME,
    T5.SR_ID,
    T5.MOBILE_NO,
    T2.ENTRY_DATE,
    T2.OUTLET_ID,
    T3.ROUTE_NAME,
    T1.OUTLET_NAME,
    T1.OUTLET_ADDRESS,
    T1.PROPRITOR_NAME,
    T1.MOBILE_NUMBER,
    T2.status || T8.REASON   -- here
order by T1.OUTLET_NAME

【讨论】:

以上是关于Oracle- 为啥在组合列中显示此错误“ORA-00904: "OUTLET_STATUS": invalid identifier"?的主要内容,如果未能解决你的问题,请参考以下文章

为啥 Apex/Oracle 会出现此错误?

为啥这会导致 oracle 错误? ORA-00907

编译触发器时出现 Oracle 错误 ORA-00922

为啥 OraOLEDB.Oracle GetRecordSet() 会抛出“ORA-00907:缺少右括号”错误?

求oracle 数据库高手 围观 此问题: 执行下面代码 报此错误:ora-01722:无效数字

为啥ORACLE本地数据库连接提示ORA-12514错误?