Update columns with Null values

nath picture nath · Oct 13, 2010 · Viewed 84.8k times · Source

I tried updating a table as follows:

update userloginstats set logouttime = sysdate where logouttime = null;

It didn't update the columns with null values. What went wrong?

Answer

codaddict picture codaddict · Oct 13, 2010

Change it to

...where logouttime is null;
                    ^^^^^^^

NULL is a special value and we cannot use the usual = operator with it.

From the Oracle documentation for NULL:

To test for nulls, use only the comparison conditions IS NULL and IS NOT NULL. If you use any other condition with nulls and the result depends on the value of the null, then the result is UNKNOWN because null represents a lack of data, a null cannot be equal or unequal to any value or to another null