在 ireport 设计器中查询 运行 SQL 时出现无效标识符错误
Invalid identifier error while running SQL query in ireport designer
我 运行 在 iReport 设计器查询浏览器中关注 SQL 查询:
SELECT
A.DOC_TYPE AS DOC_TYPE,(CASE
WHEN EXTRACT(MONTH FROM A.UPLOAD_DT) = 01 THEN 'January'
WHEN EXTRACT(MONTH FROM A.UPLOAD_DT) = 02 THEN 'February'
WHEN EXTRACT(MONTH FROM A.UPLOAD_DT) = 03 THEN 'March'
WHEN EXTRACT(MONTH FROM A.UPLOAD_DT) = 04 THEN 'April'
WHEN EXTRACT(MONTH FROM A.UPLOAD_DT) = 05 THEN 'May'
WHEN EXTRACT(MONTH FROM A.UPLOAD_DT) = 06 THEN 'June'
WHEN EXTRACT(MONTH FROM A.UPLOAD_DT) = 07 THEN 'July'
WHEN EXTRACT(MONTH FROM A.UPLOAD_DT) = 08 THEN 'Augst'
WHEN EXTRACT(MONTH FROM A.UPLOAD_DT) = 09 THEN 'September'
WHEN EXTRACT(MONTH FROM A.UPLOAD_DT) = 10 THEN 'October'
WHEN EXTRACT(MONTH FROM A.UPLOAD_DT) = 11 THEN 'November'
WHEN EXTRACT(MONTH FROM A.UPLOAD_DT) = 12 THEN 'December'
END) AS M, EXTRACT(YEAR FROM A.UPLOAD_DT) AS Y,SUM(A.TOTAL) AS TOTAL
FROM
(select DOC_TYPE, UPLOAD_DT, count(DOC_TYPE) as TOTAL
from CASE_UPLOADS
where UPLOAD_DT >= '01-JAN-15'
AND UPLOAD_DT <= '31-MAR-15'
AND DOC_TYPE = 'QR7'
OR DOC_TYPE = 'SAR7'
group by DOC_TYPE,UPLOAD_DT
order by DOC_TYPE) A
GROUP BY DOC_TYPEY,M,TO_CHAR (A.UPLOAD_DT, 'MM')
ORDER BY DOC_TYPE,Y, TO_CHAR (A.UPLOAD_DT, 'MM')
它向我抛出以下错误:
ORA:00904:"M":Invalid Identifier
有人可以告诉我为什么会出现此错误吗?我可以通过什么方式解决?
我处理过与此类似的其他查询,并且效果很好。这是查询:
SELECT CASE WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 01 THEN 'January'
WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 02 THEN 'February'
WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 03 THEN 'March'
WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 04 THEN 'April'
WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 05 THEN 'May'
WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 06 THEN 'June'
WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 07 THEN 'July'
WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 08 THEN 'Augst'
WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 09 THEN 'September'
WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 10 THEN 'October'
WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 11 THEN 'November'
WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 12 THEN 'December'
END AS MONTH,
EXTRACT(YEAR FROM app_pgm_req_dt) AS YEAR,
COUNT(*)
FROM app_pgm_choice
GROUP BY YEAR, MONTH, TO_CHAR (app_pgm_req_dt, 'MM')
ORDER BY YEAR, TO_CHAR (app_pgm_req_dt, 'MM');
大概是因为 SELECT
中定义的列别名在 group by
中通常不允许:
GROUP BY DOC_TYPEY, M, TO_CHAR(A.UPLOAD_DT, 'MM')
--------------------^
这取决于数据库。
相反,您可以使用以下表达式:
GROUP BY DOC_TYPEY, EXTRACT(MONTH FROM A.UPLOAD_DT), EXTRACT(YEAR FROM A.UPLOAD_DT)
因为您还需要 group by
中的年份。
至于为什么其他版本有效,我想您可能在 app_pgm_choice
中有一个名为 month
的列。或者,它可能连接到 支持 group by
子句中的别名的数据库。
顺便问一下,您没有使用 to_char(a.upload_dt, 'Mmm')
是什么原因?
我 运行 在 iReport 设计器查询浏览器中关注 SQL 查询:
SELECT
A.DOC_TYPE AS DOC_TYPE,(CASE
WHEN EXTRACT(MONTH FROM A.UPLOAD_DT) = 01 THEN 'January'
WHEN EXTRACT(MONTH FROM A.UPLOAD_DT) = 02 THEN 'February'
WHEN EXTRACT(MONTH FROM A.UPLOAD_DT) = 03 THEN 'March'
WHEN EXTRACT(MONTH FROM A.UPLOAD_DT) = 04 THEN 'April'
WHEN EXTRACT(MONTH FROM A.UPLOAD_DT) = 05 THEN 'May'
WHEN EXTRACT(MONTH FROM A.UPLOAD_DT) = 06 THEN 'June'
WHEN EXTRACT(MONTH FROM A.UPLOAD_DT) = 07 THEN 'July'
WHEN EXTRACT(MONTH FROM A.UPLOAD_DT) = 08 THEN 'Augst'
WHEN EXTRACT(MONTH FROM A.UPLOAD_DT) = 09 THEN 'September'
WHEN EXTRACT(MONTH FROM A.UPLOAD_DT) = 10 THEN 'October'
WHEN EXTRACT(MONTH FROM A.UPLOAD_DT) = 11 THEN 'November'
WHEN EXTRACT(MONTH FROM A.UPLOAD_DT) = 12 THEN 'December'
END) AS M, EXTRACT(YEAR FROM A.UPLOAD_DT) AS Y,SUM(A.TOTAL) AS TOTAL
FROM
(select DOC_TYPE, UPLOAD_DT, count(DOC_TYPE) as TOTAL
from CASE_UPLOADS
where UPLOAD_DT >= '01-JAN-15'
AND UPLOAD_DT <= '31-MAR-15'
AND DOC_TYPE = 'QR7'
OR DOC_TYPE = 'SAR7'
group by DOC_TYPE,UPLOAD_DT
order by DOC_TYPE) A
GROUP BY DOC_TYPEY,M,TO_CHAR (A.UPLOAD_DT, 'MM')
ORDER BY DOC_TYPE,Y, TO_CHAR (A.UPLOAD_DT, 'MM')
它向我抛出以下错误:
ORA:00904:"M":Invalid Identifier
有人可以告诉我为什么会出现此错误吗?我可以通过什么方式解决?
我处理过与此类似的其他查询,并且效果很好。这是查询:
SELECT CASE WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 01 THEN 'January'
WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 02 THEN 'February'
WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 03 THEN 'March'
WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 04 THEN 'April'
WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 05 THEN 'May'
WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 06 THEN 'June'
WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 07 THEN 'July'
WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 08 THEN 'Augst'
WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 09 THEN 'September'
WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 10 THEN 'October'
WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 11 THEN 'November'
WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 12 THEN 'December'
END AS MONTH,
EXTRACT(YEAR FROM app_pgm_req_dt) AS YEAR,
COUNT(*)
FROM app_pgm_choice
GROUP BY YEAR, MONTH, TO_CHAR (app_pgm_req_dt, 'MM')
ORDER BY YEAR, TO_CHAR (app_pgm_req_dt, 'MM');
大概是因为 SELECT
中定义的列别名在 group by
中通常不允许:
GROUP BY DOC_TYPEY, M, TO_CHAR(A.UPLOAD_DT, 'MM')
--------------------^
这取决于数据库。
相反,您可以使用以下表达式:
GROUP BY DOC_TYPEY, EXTRACT(MONTH FROM A.UPLOAD_DT), EXTRACT(YEAR FROM A.UPLOAD_DT)
因为您还需要 group by
中的年份。
至于为什么其他版本有效,我想您可能在 app_pgm_choice
中有一个名为 month
的列。或者,它可能连接到 支持 group by
子句中的别名的数据库。
顺便问一下,您没有使用 to_char(a.upload_dt, 'Mmm')
是什么原因?