错误消息/故障排除我的代码
Posted
技术标签:
【中文标题】错误消息/故障排除我的代码【英文标题】:Error message / troubleshooting my code 【发布时间】:2014-08-01 16:22:30 【问题描述】:我在运行查询时收到以下错误消息:
ORA-00904:“ACCNT”:标识符无效 00904. 00000 - “%s:无效标识符” *原因: *行动: 行错误:33 列:29
这是我正在运行的代码:
select
pdl.business_unit as BU,
pdl.deptid as BR,
pb.in_service_dt as IN_SERVICE_DATE,
pdl.asset_id as ASSET_ID,
pa.descr as DESCRIPTION,
pa.serial_id as SERIAL_NUMBER,
pdl.account as ACCNT,
case when pdl.trans_in_out = 'I' then 'TRANSFERRED TO' else pdl.deptid end as DEPTID,
MAX(CASE WHEN (pdl.trans_in_out = 'O') then pdl.deptid END) as ACCT_FROM,
MAX(CASE WHEN (pdl.trans_in_out = 'I') then pdl.deptid END) as ACCT_TO
From ps_dist_ln pdl,
ps_book pb,
ps_asset pa
where
pdl.business_unit = 'A0465'
and pdl.fiscal_year = '2014'
and pdl.asset_id = '000000000151'
and pdl.accounting_period = '12'
and pdl.trans_type = 'RCT'
and pdl.distribution_type = 'FA'
and pdl.book = 'PERFORM'
and pdl.asset_id = pb.asset_id and pdl.business_unit = pb.business_unit
and pdl.asset_id = pa.asset_id and pdl.business_unit = pa.business_unit
GROUP BY
BU,
BR,
IN_SERVICE_DATE,
ASSET_ID,
DESCRIPTION,
SERIAL_NUMBER,
ACCNT,
DEPTID
我无法弄清楚为什么会出现此错误。所有字段名称和别名看起来都正确。任何帮助将不胜感激。谢谢你的帮助。
【问题讨论】:
从这里:***.com/questions/25082571/… -- 我回答了,没有注意到 Oracle 标签。我给出了 SQL-Server 的答案。不确定 Oracle 是否支持“CASE”语法。请清楚 RDBMS。我删除了 SQL-Server 标记。 【参考方案1】:GROUP BY 不识别 SELECT 子句中定义的别名。
如果您的 SELECT 语句这样说:
SELECT
pdl.business_unit as BU,
pdl.deptid as BR,
pb.in_service_dt as IN_SERVICE_DATE,
pdl.asset_id as ASSET_ID,
pa.descr as DESCRIPTION,
pa.serial_id as SERIAL_NUMBER,
pdl.account as ACCNT,
case when pdl.trans_in_out = 'I' then 'TRANSFERRED TO' else pdl.deptid end AS DEPTID
那么你的 GROUP BY 语句应该这样写:
GROUP BY
pdl.business_unit,
pdl.deptid,
pb.in_service_dt,
pdl.asset_id,
pa.descr,
pa.serial_id,
pdl.account,
case when pdl.trans_in_out = 'I' then 'TRANSFERRED TO' else pdl.deptid end
【讨论】:
不错。还有一个很好的例子说明为什么别名不起作用:***.com/a/2681576/429982 不客气,@Shaves。如果此答案或任何答案解决了您的问题,请单击复选标记考虑accepting it。这向更广泛的社区表明您找到了解决方案,并为回答者和您自己赢得了一些声誉。以上是关于错误消息/故障排除我的代码的主要内容,如果未能解决你的问题,请参考以下文章
如何对事件日志中的 .NET 2.0 错误报告消息进行故障排除?