Oracle NUMBER(p) 存储大小?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24240087/
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-10 05:40:23  来源:igfitidea点击:

Oracle NUMBER(p) storage size?

oraclenumberssizestorage

提问by alex_pt

I've searched for it but i can't find a conclusive answer to my question...

我已经搜索过了,但我找不到我的问题的最终答案......

I need to know what is the storage size of a number(p) field in Oracle.

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

Examples: NUMBER(1), NUMBER(3), NUMBER(8), NUMBER(10) etc...

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

回答by Alex Poole

The storage used depends on the actual numeric value, as well as the column precision and scale of the column.

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

The Oracle 11gR2 concepts guide says:

甲骨文11gR2的理念指导说

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.

Oracle 数据库以可变长度格式存储数字数据。每个值都以科学记数法存储,其中 1 个字节用于存储指数。数据库最多使用 20 个字节来存储尾数,尾数是包含其有效数字的浮点数的一部分。Oracle 数据库不存储前导零和尾随零。

The 10gR2 guide goes further:

10gR2中引导更进一步

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.

考虑到这一点,可以使用以下公式计算特定数值数据值 NUMBER(p) 的列大小(以字节为单位),其中 p 是给定值的精度:

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

其中,如果数字为正,则 s 等于 0,如果数字为负,则 s 等于 1。

零和正负无穷大(仅在从第 5 版 Oracle 数据库导入时生成)使用唯一表示法存储。零和负无穷大各需要 1 个字节;正无穷大需要 2 个字节。

If you have access to My Oracle Support, there is more information in note 1031902.6.

如果您有权访问 My Oracle Support,请参阅注释 1031902.6 中的更多信息。

You can see the actual storage used with vsizeor dump.

您可以通过vsize或来查看实际使用的存储空间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 

Notice that the storage varies depending on the value, even though they are all in a number(10)column, and that two 3-digit numbers can need different amounts of storage.

请注意,存储因值而异,即使它们都在一number(10)列中,并且两个 3 位数字可能需要不同的存储量。

回答by Nishanthi Grashia

NUMBER  
999...(38 9's) x10125 
maximum value   Can be represented to full 38-digit precision (the mantissa).

-999...(38 9's) x10125 
minimum value   Can be represented to full 38-digit precision (the mantissa).


Precision   38 significant digits    ==> NUMBER(38) is the max

Refer hereand also may be here

参考这里,也可能是这里

回答by Mostafa Vatanpour

The numberdata type in Oracle is a special data type that is variable length like varchar. Then if you store the same data in number(5)and number(20)the storage is the same like declaring a column as varchar(100)and varchar(200).

number在Oracle数据类型是一个特殊的数据类型,它是像可变长度varchar。然后,如果您将相同的数据存储在其中number(5)number(20)并且存储与将列声明为varchar(100)and 相同varchar(200)

So specifying the p parameter in number(p,s)has no effect on storage size and is only for applying constraint on the data. But specifying the s parameter can reduce the size by rounding the data.

因此指定 p 参数number(p,s)对存储大小没有影响,仅用于对数据应用约束。但是指定 s 参数可以通过舍入数据来减小大小。

the minimum storage size of number data type is 1 byte and the maximum is 21 bytes. So if you do not want to apply constraint then use numberdata type without p parameter.

number 数据类型的最小存储大小为 1 个字节,最大为 21 个字节。因此,如果您不想应用约束,请使用number不带 p 参数的数据类型。