SQL Command not properly ended?
Asked Answered
F

2

9

I am using a SQL statement with a Temporary relation, and am getting the error ORA-009933: SQL command not properly ended

I don't see anything wrong with the statement, so any assistance is greatly appreciated. The statement is:

SELECT Temp.name,
       Temp.AvgSalary
FROM   (SELECT A.aid,
               A.aname       AS name,
               AVG(E.salary) AS AvgSalary
        FROM   Aircraft A,
               Certified C,
               Employees E) AS Temp; 

Thanks

Forspent answered 21/3, 2012 at 19:42 Comment(2)
really? no join conditions and no group by?Morie
You are right, I do need a group by. ThanksForspent
M
21

oracle does not support as for table aliases, only for column aliases and they are optional for that use => delete all as keywords ;)

Morie answered 21/3, 2012 at 19:45 Comment(1)
By this, for clarification, I found I could do SELECT LNAME || ', ' || FNAME, ORG FROM myTable instead. I had been doing something like this: SELECT (SELECT LNAME || ', ' || FNAME FROM myTable AS NAME), ORG FROM myTable, and this latter format with the subquery it turned out I didn't even need was causing this SQL Command not properly ended error, for me.Sync
C
8

You shouldn't put the AS temp. When putting alias to a table (or subquery) you should only write the alias. This should work:

SELECT Temp.name, Temp.AvgSalary 
FROM ( SELECT A.aid, A.aname AS name, AVG(E.salary) AS AvgSalary 
       FROM Aircraft A, Certified C, Employees E)  Temp;

Best regards,

Clareta answered 21/3, 2012 at 19:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.