简体   繁体   中英

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) ...

 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:

(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. What gives?

Either remove the quotes around "theWeightOfTheAuthor" when you define it, or add quotes when you use it. 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.

A basic rule of Oracle programming is - never quote identifiers. 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" . When you use double quotes for a column name, Oracle preserves case. When you refer to it without quotes, as athw.theWeightOfTheAuthor , Oracle automatically converts it to upper-case. 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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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