Hi Statey603
When I try the following - if the pgm_cde value is NULL,
nothing is returned.
WHERE pgm_cde is null or (pgm_cde not in ('A','C'))
That's exactly what I've been running, which works for me. Hmm.
Try this please:
select nvl(pgm_cde, 'NULL'), count(*)
from
group by pgm_cde
order by pgm_cde;
And a DESC of the table would also help. Can you also mention what
versions of Oracle database, Oracle client and Toad you are using
please.
isn't this because the not in to the right of the OR is
trying to evaluate the NULL as a string/character
It is strange, but what is happening in the evaluation is this:
Q1. Is the value NULL?
YES: Select this row.
NO: Q2. Is the value NOT 'A' AND NOT 'C'
YES: Reject this row
NO: Include this row.
Now even if Oracle is short-circuiting the tests (if the first one is
true, don't bother with the second because the whole OR will be true)
only one of the two tests will be true because a NULL implies NO VALUE
and anything but 'A' or 'C' implies a value.
The order you specify the tests in this case, make no difference, you
could check for NULLs last or NOT IN ('A','C') last and still get the
same results.
Looking at an explain plan for the statements on a test table, I see
this:
SELECT STATEMENT CHOOSE
2 COUNT
1 TABLE ACCESS FULL SYSTEM.NORM Filter Predicates:
"NORM"."A" IS NULL OR "NORM"."A"<>'A' AND "NORM"."A"<>'C'
I'm a little confused as to why you are not getting any results though.
Do you have other clauses in the WHERE that are filtering out before you
get to the NULL or NOT IN check.
Cheers,
Norm. [TeamT]
Information in this message may be confidential and may be legally privileged. If you have received this message by mistake, please notify the sender immediately, delete it and do not copy it to anyone else. We have checked this email and its attachments for viruses. But you should still check any attachment before opening it. We may have to make this message and any reply to it public if asked to under the Freedom of Information Act, Data Protection Act or for litigation. Email messages and attachments sent to or from any Environment Agency address may also be accessed by someone other than the sender or recipient, for business purposes. If we have sent you information and you wish to use it please read our terms and conditions which you can get by calling us on 08708 506 506. Find out more about the Environment Agency at www.environment-agency.gov.uk
Information in this message may be confidential and may be legally privileged. If you have received this message by mistake, please notify the sender immediately, delete it and do not copy it to anyone else.
We have checked this email and its attachments for viruses. But you should still check any attachment before opening it.
We may have to make this message and any reply to it public if asked to under the Freedom of Information Act, Data Protection Act or for litigation. Email messages and attachments sent to or from any Environment Agency address may also be accessed by someone other than the sender or recipient, for business purposes.
If we have sent you information and you wish to use it please read our terms and conditions which you can get by calling us on 08708 506 506. Find out more about the Environment Agency at www.environment-agency.gov.uk