I am having problems safely converting text values to numbers with the TO_NUMBER function.
select to_number('BAD') from dual
Result: ORA-01722: invalid number. This makes sense.
select to_number('6E9547') from dual
Result: ORA-01722: invalid number. This makes sense too considering that the E is treated as an exponent marker.
So I create a function to test if a number is valid:
CREATE OR REPLACE FUNCTION is_number( str IN VARCHAR2 ) RETURN NUMBER IS
BEGIN
RETURN TO_NUMBER(str);
EXCEPTION
WHEN OTHERS THEN RETURN NULL;
END;
Now it is time for a retest:
select is_number('BAD') from dual
Result: NULL as expected
select is_number('6E9547') from dual
Result: 1E126
This last one is unexpected. I expect NULL but get a 'random' number?
All this on 10.2.0.4 (patch set 20) on Windows 2003 server.