Home > Blogroll, sql > positive infinity

positive infinity

August 30th, 2007

I have read a long long time ago the following note on positive infinity http://www.ixora.com.au/notes/infinity.htm

Today I finally succeeded in inserting positive infinity in a number field


create table t as select 
  STATS_F_TEST(cust_gender, 1, 'STATISTIC','F') f
from (
  select 'M' cust_gender from dual union all 
  select 'M' from dual union all 
  select 'F' from dual union all 
  select 'F' from dual)
;

I am so happy :-D

Let’s try a few queries


SQL> desc t
 Name              Null?    Type
 ----------------- -------- ------
 F                          NUMBER

SQL> select f from t;

         F
----------
         ~

SQL> select f/2 from t;
select f/2 from t
        *
ERROR at line 1:
ORA-01426: numeric overflow

SQL> select -f from t;

        -F
----------
        -~

SQL> select cast(f as binary_double) from t;

CAST(FASBINARY_DOUBLE)
----------------------
                   Inf

SQL> select * from t
  2  where cast(f as binary_double) = binary_double_infinity;

         F
----------
         ~

Now expect a lot of bugs with your oracle clients 8-)

Toad 9 for example returns


SQL>  select f from t
select f from t
              *
Error at line 1
OCI-22065: number to text translation for the given 
format causes overflow

Bookmark and Share

  1. August 30th, 2007 at 15:50 | #1

    COOL ;-)

  2. December 11th, 2007 at 14:19 | #2

    probably easy to use utl_raw ;-)

    SQL> select utl_raw.cast_to_number('FF65') from dual;
    
    UTL_RAW.CAST_TO_NUMBER('FF65')
    ------------------------------
                                 ~
    
    SQL> select utl_raw.cast_to_number('00') from dual;
    
    UTL_RAW.CAST_TO_NUMBER('00')
    ----------------------------
                              -~
    

  1. June 9th, 2009 at 12:55 | #1