简体   繁体   English

奇怪的无效标识符错误oracle SQL

[英]Strange Invalid identifier error oracle SQL

I have this portion of a Oracle SQL query (lots more above it that doesn't apply to the question) ... 我有Oracle SQL查询的这一部分(在它上面有很多内容,不适用于该问题)...

 authorw as (
    select a.id, (sum(p.w)) "theWeightOfTheAuthor"
    from ac a, pc p, authorpublication ap
    where a.id = ap.aid and ap.pid = p.id
    group by a.id)

select authorCount.id "ID", auth.name "NAME", authorCount.c "TOTAL_NUMBER_OF_PUBS", 
    athw.theWeightOfTheAuthor "W_SCORE", 
    (authorCount.C / athw.theWeightOfTheAuthor) "MULT"
from ac authorCount, authorw athw, Author auth
where authorCount.id = athw.id and authorCount.id = auth.id
order by TOTAL_NUMBER_OF_PUBS desc;

where I am receiving an error: 我收到错误的地方:

ORA-00904: "ATHW"."THEWEIGHTOFTHEAUTHOR": invalid identifier
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:
Error at Line: 404 Column: 22

Line 404 being the fourth from last line: 404行是最后一行的第四行:

(authorCount.C / athw.theWeightOfTheAuthor) "MULT"

NOTE: I can access athw.id just fine, and if I execute up to the authorw creation, the table is printed out correctly with the theWeightOfTheAuthor column as expected. 注意:我可以很好地访问athw.id ,并且如果执行了authorw创建操作,表theWeightOfTheAuthor预期正确打印出来,并带有theWeightOfTheAuthor列。 What gives? 是什么赋予了?

Either remove the quotes around "theWeightOfTheAuthor" when you define it, or add quotes when you use it. 定义时,请删除"theWeightOfTheAuthor"周围的引号,或者在使用时添加引号。 Quoting the name when defining it makes the name case-sensitive, and because Oracle changes all non-quoted identifiers to UPPER CASE, your reference to the field is actually looking for ATHW.THEWEIGHTOFTHEAUTHOR, which doesn't exist. 在定义名称时引用该名称会使名称区分大小写,并且由于Oracle将所有未引用的标识符更改为UPPER CASE,因此您对该字段的引用实际上是在寻找ATHW.THEWEIGHTOFTHEAUTHOR,该名称不存在。

A basic rule of Oracle programming is - never quote identifiers. Oracle编程的基本规则是-永远不要引用标识符。 It's a pain. 真痛苦 Just don't do it. 只是不要这样做。

Best of luck. 祝你好运。

You've specified the column alias in double quotes, with mixed case, as "theWeightOfTheAuthor" . 您已将列别名用双引号(大小写混合)指定为"theWeightOfTheAuthor" When you use double quotes for a column name, Oracle preserves case. 当您在列名中使用双引号时,Oracle会保留大小写。 When you refer to it without quotes, as athw.theWeightOfTheAuthor , Oracle automatically converts it to upper-case. 当您不带引号引用它时,如athw.theWeightOfTheAuthor ,Oracle会自动将其转换为大写。 So the two don't match. 所以两者不匹配。

My suggestion is to remove the double quotes from the alias, so it will also be interpreted as upper-case. 我的建议是从别名中删除双引号,因此也将其解释为大写。 Alternatively, you could use double quotes for all references to this column, but I don't see any benefit to using mixed case in the column name. 另外,您可以在此列的所有引用中使用双引号,但是在列名中使用混合大小写不会带来任何好处。 (You can still write it as mixed case, for readability, but Oracle will see it as all upper case.) (出于可读性考虑,您仍然可以为大写形式,但Oracle会将其视为大写形式。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM