Home > sql > to_number(to_char(:n))

to_number(to_char(:n))

Is it safe to do a TO_NUMBER(TO_CHAR(:n)) ?

var n number
exec :n :=  9.9999999999999999999999999999999999e125
select to_number(to_char(:n)) from dual;
ORA-01722: invalid number

Why?
SQL Reference
If a positive NUMBER value is extremely large and cannot be represented in the specified format, then the infinity sign (~) replaces the value

select to_char(:n) from dual;
TO_CHAR(:N)
--------------
~

I wrote more about infinity here

Bookmark and Share

  1. June 10th, 2009 at 01:02 | #1

    “more about infinity” ?

    9.9999999999999999999999999999999999e125 has the same distance from infinity as
    1 has.

  2. June 10th, 2009 at 08:55 | #2

    yes, but it is so large that to_char displays it as “infinity” ;-)

  1. No trackbacks yet.