June 20, 2012

The NULL Logic In The SQL

On today's course "Anatomy Of Database" by Targo Tennisberg among other things I have learned very simple thing about NULL in SQL:

I've always thought that NULL means nothing, but actually it means unknown.

And that is why we can not compare some value with NULL - we can not use expressions like value = NULL or value > NULL, because it basically means that we are askind "does value equals to unknown?" It is impossible to answer that question. So we need to use expression value IS NULL, which means "does value is unknown?" Yes, it can be unknown.

The thing that impresses me - that I've always knew, that I should use IS NULL, not = NULL, but I've never thought why (when I started to use PL/SQL Developer, for the first time I wrote = NULL in the querry).

No comments:

Post a Comment