现在的位置: 首页 > 综合 > 正文

Oracle binary_float和binary_double类型的特殊值实例

2013年08月27日 ⁄ 综合 ⁄ 共 2316字 ⁄ 字号 评论关闭

--==============================

--author:_yeeXun

--date:12/29/2010 9:59:00 AM

--address:Jau 17-304

--==============================

SQL> create table binary_test

  2  (bin_float binary_float,

  3  bin_double binary_double);

Table created

 

SQL> insert into binary_test(

  2  bin_float,bin_double)

  3  values(39.5f,15.7d);

1 row inserted

 

 

注意:在一个数字的末尾加上一个f或d,分别表示此数字为binary_float或binary_double类型。

SQL> insert into binary_test(bin_float,bin_double)

  2  values(binary_float_infinity,binary_double_infinity);

1 row inserted

 

SQL> select * from binary_test;

 BIN_FLOAT BIN_DOUBLE

---------- ----------

      39.5       15.7

     1E126      1E126


向表中添加nan

SQL> insert into binary_test(bin_float,bin_double)

  2  values(binary_float_nan,binary_double_nan);

1 row inserted


 

当我向表中添加这两个数据binary_float_nan,binary_double_nan之后,执行查询操作:

SQL> select * from binary_test; 

select * from binary_test

ORA-01722: 无效数字


这里明显出了问题,明明数据表里面有3条数据的,怎么会查询不出来呢?

是我最后插入的数据影响到了这个查询吗?如果是的话,那么我先将这个nan值插入到表中,看看有什么效果。首先声明一下,我用的是PL/SQL
Developer做的测试;


SQL> rollback;

Rollback complete


查看表中是否有数据

SQL> select count(*) from binary_test;

   COUNT(*)

----------

         0


再次插入nan值:

SQL> insert into binary_test(bin_float,bin_double)

  2  values(binary_float_nan,binary_double_nan); 

1 row inserted

 

SQL> select * from binary_test;

select * from binary_test

ORA-01722: 无效数字


在插入其他数据:

SQL> insert into binary_test(bin_float,bin_double)

  2  values(36.12f,564.1545d);

1 row inserted

 

SQL> select * from binary_test;

select * from binary_test

ORA-01722: 无效数字

 

来看看数据表里面有几条数据

SQL> select count(*) from binary_test;

  COUNT(*)

----------

         2


那为啥用select * 查询会显示"无效数字"呢?

我们将其转化为字符串,看看有什么效果:

SQL> select to_char(bin_float) cl,to_char(bin_double) c2 from binary_test where rownum<=2;

 

CL                                       C2

-----------------------------------------------------------------

Nan                                      Nan

3.61199989E+001                        5.6415449999999998E+00

 

这正是刚刚才我向表里面添加的那两条数据


当我用oracle自带的Oracle SQL*Plus执行上面未能成功的查询时,我看到了奇迹:
SQL> select * from binary_test;

 BIN_FLOAT   BIN_DOUBLE

--------------    ------------------

           Nan                     Nan

3.612E+001  5.642E+002

 

oracleFans(http://hi.csdn.net/Oraclefans_)
这样告诉我:

binary_float_nanbinary_double_nan 在数据里存储的是IS NaN IS INF
不要用 PL/SQL Developer 作此实验,在plsql下不支持数据和nan同时显示,
可以用 SQL*Plus。

 

看来 PL/SQL Developer 得改进改进。

所以,我们最好用oracle自带的Oracle
SQL*Plus来做测试!


抱歉!评论已关闭.