Oracle NUMBER(p) 存储大小?

标签 oracle numbers size storage

我已经搜索过了,但找不到我的问题的结论性答案...

我需要知道Oracle中number(p)字段的存储大小是多少。

示例:NUMBER(1)、NUMBER(3)、NUMBER(8)、NUMBER(10) 等...

最佳答案

使用的存储取决于实际数值以及列精度和列小数位数。

Oracle 11gR2 concepts guide says:

Oracle Database stores numeric data in variable-length format. Each value is stored in scientific notation, with 1 byte used to store the exponent. The database uses up to 20 bytes to store the mantissa, which is the part of a floating-point number that contains its significant digits. Oracle Database does not store leading and trailing zeros.

10gR2 guide goes further:

Taking this into account, the column size in bytes for a particular numeric data value NUMBER(p), where p is the precision of a given value, can be calculated using the following formula:

ROUND((length(p)+s)/2))+1

where s equals zero if the number is positive, and s equals 1 if the number is negative.

Zero and positive and negative infinity (only generated on import from Version 5 Oracle databases) are stored using unique representations. Zero and negative infinity each require 1 byte; positive infinity requires 2 bytes.

如果您有权访问 My Oracle Support,注释 1031902.6 中提供了更多信息。

You can see the actual storage used with vsize or dump

create table t42 (n number(10));

insert into t42 values (0);
insert into t42 values (1);
insert into t42 values (-1);
insert into t42 values (100);
insert into t42 values (999);
insert into t42 values (65535);
insert into t42 values (1234567890);

select n, vsize(n), dump(n)
from t42
order by n;

          N   VSIZE(N)                           DUMP(N) 
------------ ---------- ---------------------------------
         -1          3           Typ=2 Len=3: 62,100,102 
          0          1                  Typ=2 Len=1: 128 
          1          2                Typ=2 Len=2: 193,2 
        100          2                Typ=2 Len=2: 194,2 
        999          3           Typ=2 Len=3: 194,10,100 
      65535          4          Typ=2 Len=4: 195,7,56,36 
 1234567890          6   Typ=2 Len=6: 197,13,35,57,79,91 

请注意,存储空间会根据值而变化,即使它们都位于 number(10) 列中,并且两个 3 位数字可能需要不同的存储量。

关于Oracle NUMBER(p) 存储大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24240087/

相关文章:

performance - 如何将 Oracle 用户配置文件投入实际使用?

ios - 当使用逗号而不是小数点时,我的 iOS 应用程序会计算数字吗?

jquery - 数据表...排序不适用于数字逗号...为什么?

使用 FFMPeg 编码器库时 Android apk 文件太大

linux - 自定义 Liquibase 控制表(DATABASECHANGELOG 和 DATABAEECHANGELOGLOCK)

sql - 运行 liquibase 脚本时出现无效字符

java - Oracle getConnection 慢

JavaScript 将字符串添加到数字

image - 如何在prefixIcon内的flutter TextFormField中添加图像

java - Java 上的字体大小(度量单位)