Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle PL/SQL where condition: not equal to 0 or null

I am selecting id where it cannot be equal to 0, nor can the value be (null). I wrote:

WHERE id IS NOT NULL (+) and id not in ('0')

I got 2 errors

Error(9,5): PL/SQL: SQL Statement ignored

Error(38,119): PL/SQL: ORA-00933: SQL command not properly ended I change it to:

WHERE id IS NOT NULL (+) and id is not ('0')  

Same errors occurred. What should I write as the WHERE clause?

like image 774
Dylan Czenski Avatar asked May 10 '26 19:05

Dylan Czenski


2 Answers

You can simplify the condition to just:

WHERE id != 0

because comparisions with NULL (using both = or != operators) always evaluates to NULL (which is treated in SQL as "false" in conditions),
therefore NULL != 0 always evaluates to FALSE and you can skip this part in this condition

WHRE id != 0 AND id IS NOT NULL

Braiam's answer Where nvl(Id,0)<>0, although correct, will prevent database from using an index on id column, and this could have bad impact on the performce.

like image 64
krokodilko Avatar answered May 14 '26 13:05

krokodilko


Shouldn't it be

WHERE id IS NOT NULL
AND id != 0
like image 40
Rahul Avatar answered May 14 '26 13:05

Rahul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!