Definition:
The Oracle NULLIF function is a null handling function which accepts two numeric arguments. If both of the arguments are equal it returns NULL; otherwise it returns the first argument. It is most commonly used for handling the ZERO_DIVIDE exception.
Example Syntax:
NULLIF(arg1, arg2)
where arg1 and arg2 are of the NUMBER datatype.
Example Usage:
The SQL example below raises a ZERO_DIVIDE exception as it foolishly tries to divide a number by zero.
SQL> SELECT 12/0 FROM DUAL;
select 12/0 from dual
*
ERROR at line 1:
ORA-01476: divisor is equal to zero
The SQL example below handles the exception raised above by using the NULLIF function in the Divisor.
SQL> SELECT 12/NULLIF(0,0) FROM DUAL;
12/NULLIF(0,0)
--------------
Related Links: