【问题标题】:ORA-9005: missing keywordORA-9005: 缺少关键字
【发布时间】:2016-01-21 17:40:23
【问题描述】:

我在尝试执行以下查询时收到 ORA-9005:缺少关键字错误。

select a.OBJID,
       A.TITLE,
       a.id_number,
       a.creation_time,
       a.case_reporter2contact,
       a.x_rev_esc_prim_reason,
       a.x_rev_esc_sec_reason,
       a.x_esc_third_reason,
       b.x_channel_source,
       b.x_verification,
       b.x_followup_status,
       b.x_saves_status,
       b.x_saves_reason,
       b.x_cust_mislead_flag,
       b.x_cust_mislead_reason,
       b.x_create_dt,
       b.x_update_dt
  from table_case a, table_x_saves_case_info b
 INNER JOIN (SELECT case_reporter2contact,
                    MAX(trunc(creation_time)) as latest_date
               FROM table_case
              WHERE calltype2gbst_elm = '268436012'
                AND x_activity_code = 'DO Drop Off'
              GROUP BY case_reporter2contact) as q
    ON a.case_reporter2contact = q.case_reporter2contact
   and q.latest_date > trunc(a.creation_time)
 where a.objid = b.x_saves_case_info2case
   and a.x_esc_primary_reason = 'Rental Inbound'
   and a.x_esc_secondary_reason in ('Buy-Out', 'Pick-Up', 'Drop-Off')
   and b.x_channel_source in ('Third Party Call',
                              'Third Party Email',
                              'Third Party Fax',
                              'Third Party Mail')
   and b.x_followup_status in ('2nd Attempt Complete', 'Complete')
 order by b.x_create_dt DESC

它突出显示来自

的“AS”

MAX(trunc(creation_time)) as latest_date

GROUP BY case_reporter2contact) as q

在甲骨文 10g 上

【问题讨论】:

  • 如果您为表“TABLE_CASE”设置别名并将其应用于选择是否有效?如 SELECT a.case_reportercontact,....from TABLE_CASE a
  • 对不起kevnisky..我没有关注..你的意思是这样吗?来自“TABLE_CASE”a、table_x_saves_case_info b 和 FROM“TABLE_CASE”。如果是这样,不,它不起作用,同样的结果。

标签: sql oracle oracle10g keyword


【解决方案1】:

在 Oracle 中,为表或内联视图设置别名时不能使用“AS”关键字。

因此您的查询需要:

select a.OBJID, A.TITLE, a.id_number, a.creation_time, a.case_reporter2contact, 
a.x_rev_esc_prim_reason, a.x_rev_esc_sec_reason, a.x_esc_third_reason, 
b.x_channel_source, b.x_verification, b.x_followup_status, b.x_saves_status, 
b.x_saves_reason, b.x_cust_mislead_flag, b.x_cust_mislead_reason, b.x_create_dt, 
b.x_update_dt 
from table_case a, table_x_saves_case_info b
INNER JOIN (
    SELECT case_reporter2contact, MAX(trunc(creation_time)) as latest_date
    FROM table_case
    WHERE calltype2gbst_elm = '268436012' 
        AND x_activity_code = 'DO Drop Off'
        GROUP BY case_reporter2contact) q -- removed the AS keyword from here
ON a.case_reporter2contact = q.case_reporter2contact and q.latest_date > trunc(a.creation_time)
where a.objid = b.x_saves_case_info2case
and a.x_esc_primary_reason = 'Rental Inbound'
and a.x_esc_secondary_reason in ('Buy-Out','Pick-Up','Drop-Off')
and b.x_channel_source in ('Third Party Call','Third Party Email','Third Party Fax','Third Party Mail')
and b.x_followup_status in ('2nd Attempt Complete','Complete')
order by b.x_create_dt DESC

【讨论】:

  • 删除了 AS 关键字并返回另一个错误 - ORA-00904: "A"."CREATION_TIME": invalid identifier
  • table_case 中是否存在该列?
  • 啊,我怀疑问题可能是您将 ANSI 连接与隐式连接混为一谈。将table_case和table_x_saves_case_info之间的join转换为ANSI join语法,你应该会发现它可以工作。
  • 如何将table_case和table_x_saves_case_info之间的join转换成ANSI join语法?
  • 你看到你有一个从 q 到 a 的内连接,但是你在 a 后面有一个逗号,在 where 子句中有一个从 a 到 b 的相应连接条件?使从 a 到 b 的连接看起来像从 a 到 q 的连接。
【解决方案2】:
select a.OBJID,
       a.TITLE,
       a.id_number,
       a.creation_time,
       a.case_reporter2contact,
       a.x_rev_esc_prim_reason,
       a.x_rev_esc_sec_reason,
       a.x_esc_third_reason,
       b.x_channel_source,
       b.x_verification,
       b.x_followup_status,
       b.x_saves_status,
       b.x_saves_reason,
       b.x_cust_mislead_flag,
       b.x_cust_mislead_reason,
       b.x_create_dt,
       b.x_update_dt
  from table_case a inner join table_x_saves_case_info b on a.objid = b.x_saves_case_info2case
 INNER JOIN (SELECT case_reporter2contact,
                    MAX(trunc(creation_time)) as latest_date
               FROM table_case
              WHERE calltype2gbst_elm = '268436012'
                AND x_activity_code = 'DO Drop Off'
              GROUP BY case_reporter2contact) q
    ON a.case_reporter2contact = q.case_reporter2contact
   and q.latest_date > trunc(a.creation_time)
   where a.calltype2gbst_elm = '268438297'
   and a.x_esc_primary_reason = 'Rental Inbound'
   and a.x_esc_secondary_reason in ('Buy-Out', 'Pick-Up', 'Drop-Off')
   and b.x_channel_source in ('Third Party Call',
                              'Third Party Email',
                              'Third Party Fax',
                              'Third Party Mail')
   and b.x_followup_status in ('2nd Attempt Complete', 'Complete')
 order by b.x_create_dt DESC

【讨论】:

    猜你喜欢
    • 2012-07-26
    • 1970-01-01
    • 1970-01-01
    • 2023-01-02
    • 1970-01-01
    • 2018-07-23
    • 2019-12-11
    • 2018-09-17
    相关资源
    最近更新 更多