【发布时间】:2023-01-12 18:12:17
【问题描述】:
您好有以下查询,但是当我执行查询时,我在 oracle 中遇到错误。问题似乎出在 ORDER BY 上,但我不确定为什么会有无效标识符,因为我的列清楚地出现在表中。我正在使用 sqldeveloper 来执行查询。
ORA-00904: "FINALRESULTS"."TESTTIME": 无效标识符
WITH tests AS ( SELECT t.place, t.stationnr, t.result, i.type, t.time, FROM result_test t INNER JOIN result_ident i ON t.place= i.place JOIN stat_testplacegroup pg on pg.place = t.place INNER JOIN result_release r ON i.type= r.type WHERE ( t.testtime BETWEEN to_date( '2022-11-20T00:00:00', 'YYYY-MM-DD"T"HH24:MI:SS ' ) AND to_date( '2022-11-26T00:00:00', 'YYYY-MM-DD"T"HH24:MI:SS' ) ) ), finalresults AS ( SELECT t.place "place", t.stationnr "stationnr", convres(t.result) "convres", t.type "type", t.testtime "testtime" FROM tests t INNER JOIN result_testecu_11 tecu ON tecu.testresid = t.testresid INNER JOIN result_pathecu pecu ON pecu.ecuid = tecu.ecuid INNER JOIN result_pathfunc func ON pecu.ecuid = func.ecuid GROUP BY t.place, t.stationnr, t.type, t.testtime t.result ) SELECT * FROM finalresults ORDER BY finalresults.testtime DESC FETCH FIRST 5 ROWS ONLY;
【问题讨论】:
-
Database Object Naming Rules:带引号的标识符以双引号 (") 开头和结尾。如果您使用带引号的标识符命名架构对象,则无论何时引用该对象都必须使用双引号。
-
finalresults.testtime应该是finalresults."testtime",因为您使用的是带引号的标识符(这被认为是不好的做法);或者您可以从查询中删除所有双引号(这被认为是更好的做法)。