Home > OS >  Error when trying to use "except" statement in Oracle SQL
Error when trying to use "except" statement in Oracle SQL

Time:10-12

i'm trying do run the following statement:

SELECT * FROM products
EXCEPT
SELECT * FROM products WHERE product_id = 310

I know that in this particular case I should use a simple "...product_id != 310" rather than an except statement, but i need this for other, more complicated queries. The problem is that running that statement leads to an "SQL command not properly ended"-Error. I can't figure out the problem...

Thanks for the help!

CodePudding user response:

Assuming you are using an Oracle version before Oracle 21, you want to use MINUS (rather than EXCEPT):

SELECT * FROM products
MINUS
SELECT * FROM products WHERE product_id = 310

If you are using Oracle 21, then you can use the ANSI set operators EXCEPT and EXCEPT ALL (which are functionally equivalent to MINUS and MINUS ALL, respectively).

  • Related