In SQL it is impossible to compare a variable with NULL like this:
CASE x WHEN NULL THEN y ELSE z END
because with the three-valued SQL logic, x = NULL will never return true. One has to do this instead:
CASE WHEN x IS NULL THEN y ELSE z END
This is problematic when x is the result of a procedure that modifies the data for example:
CASE WHEN func(i) IS NULL THEN y
WHEN func(i) = 'a' THEN z
ELSE t
END
So… func(i) will be evaluated twice? Why is there no standard requirement that CASE ... WHEN NULL compares the evaluated expression to NULL with the IS NULL operator?
Are there DBMSes that allow such a construct?
Because you’re not guaranteed that the values after WHEN are just literals, there’s no simple way to special case this without introducing more inconsistency, or re-writing SQL so that NULL==NULL.
E.g. if the expression is
CASE func(i) WHEN Col1 THEN...andCol1is null in some rows, but not in others…