0

我正在整理一个查询,该查询在很多情况下通过别名引用一个表,但随后它继续声明:

*ORA-00904: "MPAN_STATUS"."MPANCORE": 无效标识符 00904. 00000 - "%s: 无效标识符" *原因:
操作:错误行:43 列:126

查询如下:

SELECT readings.mpancore, mtds.meterid, (SELECT CASE
                                                  WHEN meter_type 
                                                  LIKE 'RCAM%' AND
                                                       retrieval_method = 'R'
                                                  THEN 'TRUE' 
                                                  ELSE 'FALSE' END
                                                  FROM edmgr.mtds
                                                 WHERE meter_removed IS NULL) "IS_SMART",
                                          (SELECT CASE 
                                                  WHEN flowversion = 'D0010'          AND
                                                       readings.filename IS NOT NULL  AND
                                                       readings.filedate >= mpan_status.ssd 
                                                  THEN 'TRUE' 
                                                  ELSE 'FALSE' END
                                                  FROM edmgr.readings, edmgr.mpan_status
                                                 WHERE readings.mpancore = mpan_status.mpancore) "D0010_RECEIVED",
                                          (SELECT CASE 
                                                  WHEN effective_from_date >= mpan_status.ssd AND
                                                       dc_id = mpan_status.confirmed_dc_id          
                                                  THEN 'TRUE' 
                                                  ELSE 'FALSE' END
                                                  FROM edmgr.D0019_reg, edmgr.mpan_status) "D0019_RECEIVED",
                                          (SELECT CASE 
                                                  WHEN file_date_time <= SYSDATE-409       
                                                  THEN 'TRUE' 
                                                  ELSE 'FALSE' END
                                                  FROM edmgr.D0019_reg) "RF_READ",
                                          (SELECT CASE 
                                                  WHEN file_date_time <= SYSDATE-220       
                                                  THEN 'TRUE' 
                                                  ELSE 'FALSE' END
                                                  FROM edmgr.D0019_reg) "R3_READ",
                                          (SELECT CASE 
                                                  WHEN file_date_time <= SYSDATE-118       
                                                  THEN 'TRUE' 
                                                  ELSE 'FALSE' END
                                                  FROM edmgr.D0019_reg) "R2_READ",
                                          (SELECT CASE 
                                                  WHEN file_date_time <= SYSDATE-56        
                                                  THEN 'TRUE' 
                                                  ELSE 'FALSE' END
                                                  FROM edmgr.D0019_reg) "R1_READ"   
        FROM edmgr.mpan_status "mpan_status" LEFT JOIN edmgr.D0019_reg "D0019"   ON mpan_status.mpancore = D0019.metering_system_id
                                             LEFT JOIN edmgr.readings "readings" ON mpan_status.mpancore = readings.mpancore
                                             LEFT JOIN edmgr.mtds "mtds"         ON readings.mpancore    = mtds.mpancore 
                                                   AND D0019.metering_system_id                          = mtds.mpancore
                                                   AND mtds.meterid                                      = readings.meterid

我真的是一个完全的新手,所以任何帮助将不胜感激。

4

1 回答 1

0

让我们开始定义ORA-00904 错误

ORA-00904 字符串:无效标识符原因:输入的列名丢失或无效。

行动:输入一个有效的列名。有效的列名必须以字母开头,少于或等于 30 个字符,并且仅包含字母数字字符和特殊字符 $、_ 和 #。

如果它包含其他字符,那么它必须用双引号引起来。它可能不是保留字。

这也是一个区分大小写的问题(在 FROM 参数中将 mpan_status 放在引号中。)在 Oracle 中,只有将列名放在引号中时它们才区分大小写。

编辑:

这是我将编写查询的建议(避免使用 ANSI 连接和子查询)。

SELECT  readings.mpancore,
        mtds.meterid,
        CASE  
            WHEN meter_type LIKE 'RCAM%' AND retrieval_method = 'R' THEN 'TRUE' 
            ELSE 'FALSE' 
        END AS "IS_SMART"
FROM    edmgr.mpan_status,
        edmgr.mtds,
        edmgr.D0019_reg,
        edmgr.readings
WHERE   mpan_status.mpancore = D0019_reg.metering_system_id
    AND mpan_status.mpancore = readings.mpancore
    AND readings.mpancore    = mtds.mpancore
    AND D0019_reg.metering_system_id = mtds.mpancore;
于 2012-08-16T09:00:01.963 回答