I know that NaN stands for Not a Number. But, I have trouble understanding when and why Oracle adds this to a row.
Is it when it encounters a value less than 0 like
Nope <=0 is still a number so not quite. NaN (or infinity) are special values that the DB uses to keep it's sanity when dealing with non-computable numbers (+-∞, or simply something that is not a number). Here's some code:
DECLARE
l_bd_test binary_double;
l_int_test INTEGER;
BEGIN
l_bd_test := 'NAN';
l_int_test := 0;
IF l_bd_test IS NAN THEN
DBMS_OUTPUT.PUT_LINE(l_bd_test || ' IS NAN');
ELSE
DBMS_OUTPUT.PUT_LINE(l_bd_test || ' IS A #');
END IF;
IF l_int_test IS NAN THEN
DBMS_OUTPUT.PUT_LINE(l_int_test || ' IS NAN');
ELSE
DBMS_OUTPUT.PUT_LINE(l_int_test || ' IS A #');
END IF;
END;
/
Substitute NAN for INFINITY or even negate it and see the results.