FLOAT 如何映射/关联到 Oracle 10g 中的 NUMBER?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17415847/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:46:24  来源:igfitidea点击:

How does FLOAT map/relate to NUMBER in Oracle 10g?

sqloracleoracle10g

提问by takteek

What is the FLOAT data type in Oracle 10g and how does it relate to NUMBER?

Oracle 10g 中的 FLOAT 数据类型是什么,它与 NUMBER 有何关系?

The only reference I can find to FLOAT in the Oracle documentation is in the BINARY_DOUBLE section of this page: http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements001.htm#i140621It seems to indicate that it stores a floating point number and allows you to specify bits of precision, but it doesn't reference the NUMBER type. The 11g docs don't mention FLOAT at all.

我能在 Oracle 文档中找到 FLOAT 的唯一参考是在本页的 BINARY_DOUBLE 部分:http: //docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements001.htm#i140621它似乎表明它存储一个浮点数并允许您指定精度位,但它不引用 NUMBER 类型。11g 文档根本没有提到 FLOAT。

The book "Expert Oracle Database Architecture: Oracle Database 9i, 10g, and 11g Programming Techniques and Solutions, Second Edition" says:

“专家 Oracle 数据库架构:Oracle 数据库 9i、10g 和 11g 编程技术和解决方案,第二版”一书说:

In addition to the NUMBER, BINARY_FLOAT, and BINARY_DOUBLE types, Oracle syntactically supports the following numeric datatypes:

When I say "syntactically supports," I mean that a CREATE statement may use these datatypes, but under the covers they are all really the NUMBER type. ...

  • FLOAT(p): Maps to the NUMBER type.

除了 NUMBER、BINARY_FLOAT 和 BINARY_DOUBLE 类型之外,Oracle 在语法上还支持以下数字数据类型:

当我说“语法支持”时,我的意思是 CREATE 语句可能会使用这些数据类型,但实际上它们都是 NUMBER 类型。...

  • FLOAT(p):映射到 NUMBER 类型。

What I don't understand is howit maps to NUMBER.

我不明白的是它如何映射到 NUMBER。

NUMBER(p)allows me to specify precision but the scale defaults to 0. It seems like FLOAT(p)is mapping to NUMBER(decimal p, *), that is, fixed precision but variable scale, which is not something the NUMBER type allows as far as I can tell.

NUMBER(p)允许我指定精度,但比例默认为 0。似乎FLOAT(p)映射到NUMBER(decimal p, *),即固定精度但可变比例,据我所知,这不是 NUMBER 类型允许的。

So, FLOAT is not just an alias but also provides behavior that NUMBER by itself does not offer?

那么,FLOAT 不仅仅是一个别名,还提供了 NUMBER 本身不提供的行为?

回答by wolφi

The documentation in 10g is a bit unclear. It has improved quite a bit from 11.1 onwards:

10g 中的文档有点不清楚。从 11.1 开始,它有了很大的改进:

http://docs.oracle.com/cd/B28359_01/server.111/b28286/sql_elements001.htm#sthref94

http://docs.oracle.com/cd/B28359_01/server.111/b28286/sql_elements001.htm#sthref94

In summary, FLOATis the same as NUMBER, with two differences

综上所述,FLOAT与 相同NUMBER,有两点不同

  1. FLOATcannot specify the scale
  2. In FLOAT, the precision is given in binary bits, in NUMBERin decimal digits, so FLOAT(126)means 126 bits of precision, NUMBER(38)means 38 decimal digits of precision
  1. FLOAT无法指定比例
  2. 在 中FLOAT,精度以二进制位给出,以NUMBER十进制数表示,因此FLOAT(126)表示精度为 126 位,NUMBER(38)表示精度为 38 位十进制数

EDITSome examples show that a FLOATis just a NUMBERin disguise.

编辑一些例子表明 aFLOAT只是NUMBER伪装的 a 。

CREATE TABLE t (
  n1 NUMBER(*,1),  f1 FLOAT(1), f2 FLOAT(2), f3 FLOAT(3),
  n2 NUMBER(*,2),  f4 FLOAT(4), f5 FLOAT(5), f6 FLOAT(6)
);
INSERT INTO t VALUES (1/3, 1/3, 1/3, 1/3, 1/3, 1/3, 1/3, 1/3);

SELECT n1, f1, f2, f3 FROM t;
  0.3 0.3 0.3 0.3

SELECT DUMP(n1), DUMP(f1), DUMP(f2), DUMP(f3) FROM t;
  Typ=2 Len=2: 192,31
  Typ=2 Len=2: 192,31
  Typ=2 Len=2: 192,31
  Typ=2 Len=2: 192,31

SELECT n2, f4, f5, f6 FROM t;
  0.33 0.33 0.33 0.33

SELECT DUMP(n2), DUMP(f4), DUMP(f5), DUMP(f6) FROM t;
  Typ=2 Len=2: 192,34
  Typ=2 Len=2: 192,34
  Typ=2 Len=2: 192,34
  Typ=2 Len=2: 192,34

Be careful, though, the conversion factor from Float's precision bits to Number's decimal digits is not 3, but around 3.32. To be exact digits= ceil(bits/ log(2,10).

但是请注意,从 Float 的精度位到 Number 的十进制数字的转换系数不是 3,而是大约 3.32。确切地说,digits= ceil( bits/ log(2,10)。