3

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?

3 Answers 3

9

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.

5

Shouldn't it be

WHERE id IS NOT NULL
AND id != 0
5

(+) is for outer joins. You should write:

Where nvl(Id,0)<>0
2
  • if I have another condition, should I just put Where [condition] AND nvl(id,0)<>0? Jan 5, 2016 at 22:03
  • 1
    Don't use [] to enclose predicates in PLSQL it wont compile. Use regular brackets if you need. You can have as many logical expressions as you need. Jan 5, 2016 at 22:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.