Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ORA-00933: SQL command not properly ended- PL/SQL

I am trying to build a complex query, but I am not sure if I am structuring it right, as I am getting the error: ORA-00933: SQL command not properly ended. The error is happening at line 2. Please, could you help me with this. Thank you!

SELECT CNP,ValoareTotala 
FROM Vanzari AS V
RIGHT OUTER JOIN Functionar AS F
ON V.CNP= F.CNP
RIGHT OUTER JOIN Achizitii AS A
ON F.CNP= A.CNP
WHERE CNP in (SELECT CNP
FROM Achizitii
WHERE CNP =
(SELECT CNP
FROM Functionar
WHERE Nume='Alex Viseu'))
GROUP BY CNP, ValoareTotala
HAVING ValoareTotala>10
ORDER BY ValoareTotala DESC;

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can’t use AS for a table alias in Oracle. You can for column aliases, where it is optional, but it is not allowed for table aliases. You can see that in the syntax diagram – that shows t_alias without an optional AS keyword.

So remove that from all three references:

SELECT CNP,ValoareTotala 
FROM Vanzari V
RIGHT OUTER JOIN Functionar F
ON V.CNP= F.CNP
RIGHT OUTER JOIN Achizitii A
ON F.CNP= A.CNP
WHERE CNP in (SELECT CNP
FROM Achizitii
WHERE CNP =
(SELECT CNP
FROM Functionar
WHERE Nume='Alex Viseu'))
GROUP BY CNP, ValoareTotala
HAVING ValoareTotala>10
ORDER BY ValoareTotala DESC;

But you will also need to make it clear which table each column comes from, particularly where the same column name appears in more than one table – and as you have the join conditions ON V.CNP= F.CNP and ON F.CNP= A.CNP the column CNP exists in all three tables; so the other references to CNP will have to specify which one you mean.

It’s also not really clear why you are using a subquery, particularly one that refers to the same tables again.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading