1
Error report:
ORA-00904: "RDD"."USED_END_DATE": invalid identifier
ORA-02063: preceding line from ADSWEBPROD
ORA-06512: at line 5

以下查询使我无效标识符错误。

DECLARE
  TYPE demo_date_array_type IS TABLE OF dc_demo_dates.demo_date_id%TYPE;
  updated_demo_dates demo_date_array_type;
BEGIN
  SELECT ddd.demo_date_id 
  BULK COLLECT INTO
    updated_demo_dates
  FROM 
    dc_demo_dates ddd 
  JOIN 
    dc_demo_reservations ddr 
  ON 
    ddd.reservation_id = ddr.reservation_id
    AND ddr.status NOT IN ('DENIED','CANCELLED')
    AND ddr.demo_type <> 'Training'
    AND ddr.environment IS NOT NULL
    AND ddd.last_update_date > SYSTIMESTAMP - 1           -- updated in the last day
    AND ddd.demo_start_date > SYSTIMESTAMP - 14 -- no older than 2 weeks
  JOIN
    (SELECT demo_date_id, used_start_date, used_end_date 
     FROM rps_by_demo_date 
     GROUP BY demo_date_id, used_start_date, used_end_date ) rdd
    ON rdd.demo_date_id = ddd.demo_date_id
  WHERE
    ddd.demo_start_date != NVL(rdd.used_start_date, SYSTIMESTAMP)  -- either start date
    OR ddd.demo_end_date != NVL(rdd.used_end_date, SYSTIMESTAMP);  -- or end date has changed
END;

如果我删除GROUP BY demo_date_id, used_start_date, used_end_dateor 如果我将最后OR一个更改为 a AND,则代码将成功执行(除非它没有给我所需的结果)

你知道会发生什么吗?谢谢

编辑:我将 group by 子句从子查询移到主查询中,并获得了我想要的结果。但我仍然不明白是什么导致了错误。

4

1 回答 1

1

尝试这个 :-

DECLARE
  TYPE demo_date_array_type IS TABLE OF dc_demo_dates.demo_date_id%TYPE;
  updated_demo_dates demo_date_array_type;
BEGIN
  SELECT ddd.demo_date_id 
  BULK COLLECT INTO
    updated_demo_dates
  FROM 
    dc_demo_dates ddd 
  JOIN 
    dc_demo_reservations ddr 
  ON 
    ddd.reservation_id = ddr.reservation_id
    AND ddr.status NOT IN ('DENIED','CANCELLED')
    AND ddr.demo_type <> 'Training'
    AND ddr.environment IS NOT NULL
    AND ddd.last_update_date > SYSTIMESTAMP - 1           -- updated in the last day
    AND ddd.demo_start_date > SYSTIMESTAMP - 14 -- no older than 2 weeks
  JOIN
    (SELECT demo_date_id, used_start_date, used_end_date 
     FROM rps_by_demo_date 
     GROUP BY demo_date_id, used_start_date, used_end_date ) rdd
    ON rdd.demo_date_id = ddd.demo_date_id
    AND (ddd.demo_start_date != NVL(rdd.used_start_date, SYSTIMESTAMP)  
    OR ddd.demo_end_date != NVL(rdd.used_end_date, SYSTIMESTAMP));  
END;

我已将 where 子句移至连接条件。在连接操作中使用 where 子句有时会导致意外结果。您的 where 子句可能无法识别 rdd。但是,您的连接条件可能会识别它。

于 2013-02-23T01:53:32.933 回答