为啥此查询中出现错误“ORA-00904: invalid identifier”?

Posted

技术标签:

【中文标题】为啥此查询中出现错误“ORA-00904: invalid identifier”?【英文标题】:Why the error "ORA-00904: invalid identifier" appears in this query?为什么此查询中出现错误“ORA-00904: invalid identifier”? 【发布时间】:2015-10-29 08:52:40 【问题描述】:

我已经构建了以下查询,但是当我尝试运行它时会引发错误:

ORA-00904: "CASE_MASTER"."FOLLOWUP_DATE":
           invalid identifier 00904. 00000 -  "%s: invalid identifier"
*Cause: 
*Action: Error at Line: 76 Column: 14

你能给我一个提示或告诉我哪里出了问题吗?

查询:

SELECT DISTINCT case_event_assess.case_id
  FROM case_event        ce
      ,case_event_assess
      ,lm_datasheet
      ,case_product      cp
      ,case_assess       ca
/* New AC Name: Exp: Testing query */
 WHERE ce.case_id = case_master.case_id
   AND ce.case_id = case_event_assess.case_id
   AND ce.seq_num = case_event_assess.event_seq_num
   AND case_event_assess.case_id = case_master.case_id
   AND ca.case_id = case_master.case_id
   AND ca.case_id = case_event_assess.case_id
   AND lm_datasheet.datasheet_id = case_event_assess.datasheet_id
   AND (sheet_name = 'IB' OR license_id = 0)
   AND ce.case_id = cp.case_id
   AND cp.seq_num = case_event_assess.prod_seq_num
   AND EXISTS (
        SELECT 1 FROM lm_product lp
         WHERE lp.drug_code = cp.co_drug_code
            OR lp.product_id = cp.pat_exposure )
   AND case_master.state_id > 1
   AND NOT EXISTS(
        SELECT DISTINCT case_event_assess.case_id
          FROM case_event_assess
         WHERE case_event_assess.case_id = case_master.case_id
           AND case_master.rpt_type_id IN (1, 3)
           AND EXISTS (
                SELECT 1 FROM lm_license
                 WHERE lm_license.license_id = case_event_assess.license_id
                   AND lm_license.country_id IN (223, 23000101)
                   AND lm_license.license_type_id IN (4, 6))
        )
   AND EXISTS(
        SELECT 1 FROM lm_license
               ,case_event_assess cea
         WHERE cea.case_id = case_master.case_id
           AND cea.prod_seq_num = case_event_assess.prod_seq_num
           AND cea.license_id = lm_license.license_id
           AND lm_license.manufacturer_id IN (10087, 200000016, 202000406, 202000608, 202000609)
           AND lm_license.country_id = 223 )
 GROUP BY case_event_assess.case_id
         ,case_event_assess.event_seq_num
         ,case_event_assess.prod_seq_num

HAVING(
(/* Serious */
MIN(ce.sc_death) = 1 OR MIN(ce.sc_threat) = 1 OR MIN(ce.sc_disable) = 1 OR MIN(ce.sc_int_req) = 1
 OR MIN(ce.sc_cong_anom) = 1 OR MIN(ce.sc_hosp) = 1 OR MIN(ce.med_serious) = 1 OR MIN(ce.sc_other) = 1
)
AND
( /* Unlisted*/
MIN(decode(lm_datasheet.datasheet_id, 0, 1, NULL, 1, abs(det_listedness_id - 2))) = 0
 OR MIN(decode(lm_datasheet.datasheet_id, 0, 3, NULL, 3, det_listedness_id)) = 3
))

【问题讨论】:

【参考方案1】:

由于您的from 子句中没有名为case_master 的表,因此您不能在您的where 子句中使用它。

【讨论】:

嗨,它应该是这样的:SELECT DISTINCT case_event_assess.case_id FROM case_event ce, case_event_assess, lm_datasheet, case_product cp, case_assess ca, case_master 我尝试将 case_master 添加到 from 子句,但现在又遇到了另一个错误:ORA-00979: not a GROUP BY expression 00979. 00000 - “not a GROUP BY expression” *原因:*行动:行错误:72 列:10 对于我收到的第二个错误。我通过执行以下操作更正了它:修改了这个:SELECT DISTINCT case_event_assess.case_id、case_master.followup_date 和分组方式:使用这个:GROUP BY case_event_assess.case_id、case_event_assess.event_seq_num、case_event_assess.prod_seq_num、case_master.followup_date 现在查询正在运行.行。感谢您的提示 piet.t

以上是关于为啥此查询中出现错误“ORA-00904: invalid identifier”?的主要内容,如果未能解决你的问题,请参考以下文章

Postgresql: 在 ""ViewShifts"" 处或附近出现语法错误 为啥我在下面的查询中会出现此错误?

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

Access 2013:为啥会出现此语法错误?

为啥我在 sql server ROW_NUMBER() 中出现错误?

为啥我的 PyMongo 查询中出现无效错误

为啥此查询会生成 PK 违规错误?