【问题标题】:Why am I receiving this error when running my Query in Oracle- "RP": invalid identifier?为什么我在 Oracle 中运行查询时收到此错误 - “RP”:标识符无效?
【发布时间】:2021-07-08 18:04:57
【问题描述】:

我有一个正在运行的查询,我希望按昨天的日期对结果进行分组。当我运行查询时,我收到一条错误消息“RP”:标识符无效。

这是我的代码:

CREATE OR REPLACE VIEW db1.table1 AS
SELECT (SELECT TO_DATE(current_date - 1)  FROM dual) as rp,
       SUM(NVL(sesions,0)) AS session_income, 
       SUM(NVL(non_sessions,0)) AS session_drop, 
       (SUM(NVL(sesions,0))- SUM(NVL(non_session,0))) as CC,
       SUM(NVL(trasnfer,0)) AS Transfer
FROM db1.table1_target
where T_DATE >= (select trunc(sysdate, 'MM') FROM dual) AND
T_DATE <= (SELECT TO_DATE(current_date - 1)  FROM dual) 
GROUP BY rp;

关于为什么我在 oracle 中运行上述查询时收到以下错误的任何想法:

"RP": Invalid identifier
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:

【问题讨论】:

  • 1) 在创建列别名 rp 之前评估 GROUP BY。
  • 2) 为什么是子查询?
  • 顺便说一句,create view 不是查询。
  • 为什么要混合使用sysdatecurrent_dateto_date() 已经是约会对象了,为什么还要对 current_date - 1 应用?

标签: sql oracle oracle11g oracle-sqldeveloper


【解决方案1】:

我不确定您为什么要使用子查询来进行简单的日期操作。您可以在聚合查询中包含“常量”:

SELECT TO_DATE(current_date - 1) as rp,
       SUM(NVL(sesions,0)) AS session_income, 
       SUM(NVL(non_sessions,0)) AS session_drop, 
       (SUM(NVL(sesions,0))- SUM(NVL(non_session,0))) as CC,
       SUM(NVL(trasnfer,0)) AS Transfer
FROM db1.table1_target
WHERE T_DATE >= trunc(sysdate, 'MM') AND
      T_DATE <= TO_DATE(current_date - 1)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-21
    • 1970-01-01
    • 2018-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-24
    • 2010-09-15
    相关资源
    最近更新 更多