Oracle数据库浮动类型限制

时间:2016-05-24 15:10:14

标签: oracle floating-point

我不确定oracle数据库中存储的最大值和最小正值是什么,以下列列类型:FLOAT,BINARY_FLOAT和BINARY_DOUBLE。

我在oracle参考文档中找不到该信息。有人能帮助我吗?

2 个答案:

答案 0 :(得分:1)

我使用了以下脚本来测试三种数据类型的最大值:

declare
  x  float         := 0;
  xx float         := 1;
  y  binary_float  := 0;
  yy binary_float  := 1;
  z  binary_double := 0;
  zz binary_double := 1;
begin
  <<outx>> loop loop if x+xx = x then exit outx; end if; if x+xx is not infinite then x:=x+xx; xx:=xx*2; else exit; end if; end loop; xx:=xx/2; end loop;
  <<outy>> loop loop if y+yy = y then exit outy; end if; if y+yy is not infinite then y:=y+yy; yy:=yy*2; else exit; end if; end loop; yy:=yy/2; end loop;
  <<outz>> loop loop if z+zz = z then exit outz; end if; if z+zz is not infinite then z:=z+zz; zz:=zz*2; else exit; end if; end loop; zz:=zz/2; end loop;
  dbms_output.put_line('float='||x);
  dbms_output.put_line('binary_float='||y);
  dbms_output.put_line('binary_double='||z);
end;
/

结果是:

float=9.999999999999999999999999999999999999999000000000000000000000000000000000000000000000000000000E+125
binary_float=3.40282347E+038
binary_double=1.7976931348623157E+308

测试我使用的最小正值:

declare
  x  float         := 1;
  xx float         := .5;
  y  binary_float  := 1;
  yy binary_float  := .5;
  z  binary_double := 1;
  zz binary_double := .5;
begin
  <<outx>> loop loop if 1-xx > 0 and x*(1-xx) = x then exit outx; end if; if 1-xx > 0 and x*(1-xx) > 0 then x:=x*(1-xx); xx:=xx*2; else exit; end if; end loop; xx:=xx/2; end loop;
  <<outy>> loop loop if 1-yy > 0 and y*(1-yy) = y then exit outy; end if; if 1-yy > 0 and y*(1-yy) > 0 then y:=y*(1-yy); yy:=yy*2; else exit; end if; end loop; yy:=yy/2; end loop;
  <<outz>> loop loop if 1-zz > 0 and z*(1-zz) = z then exit outz; end if; if 1-zz > 0 and z*(1-zz) > 0 then z:=z*(1-zz); zz:=zz*2; else exit; end if; end loop; zz:=zz/2; end loop;
  dbms_output.put_line('float='||x);
  dbms_output.put_line('binary_float='||y);
  dbms_output.put_line('binary_double='||z);
end;
/

结果是:

float=1.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E-130
binary_float=1.40129846E-045
binary_double=4.9406564584124654E-324

答案 1 :(得分:-1)

根据另一篇文章: “虽然Oracle可以存储大(和小)的数字,但它最多只能存储38位有效数字。因此,可以存储在NUMBER字段中的最大值是:

9,999,999,999,999,999,999,999,999,999,999,999,999,999

这是我可以放在那里的最大数字。在那个指数接管之后。“ 来自https://www.experts-exchange.com/questions/27958682/maximum-value-that-can-be-handled-by-oracle-datatype-number.html