Counting NULL values in Oracle

Howdy,
today I had the challenge to count null values in a orale table. At first I tried something like

SELECT
sum(field1 is null) null_counter
FROM
table

but this did not bring be very far.

also:

SELECT
sum(
case field1 
when null then 1
else 0
end
) null_counter
FROM
table

did not get me very far.

After some internet research I came across this neat little thingie:

SELECT
sum(
case nvl(field1,'null') 
when 'null' then 1 
else 0 
end
) null_counter
FROM
table

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.