CASE vs. DECODE

There is one big difference between DECODE and CASE and it has to do with how NULLs are compared. DECODE will return “true” if you compare NULL to NULL. CASE will not. For example:

DECODE(NULL, NULL, 1, 0)

will return ‘1’.

CASE NULL
    WHEN NULL THEN 1
    ELSE 0
END

will return ‘0’. You would have to write it as:

CASE
    WHEN NULL IS NULL THEN 1
    ELSE 0
END

Leave a Comment