NUMBER Data Type

本文详细介绍了Oracle数据库中NUMBER数据类型的使用方法,包括固定点数、浮点数和整数的指定形式,以及精度和标度的概念。NUMBER类型可以存储从0到接近1.0x10^126的数值,每个值占用1到22字节不等。文章还解释了如何定义固定点数的精度和标度来增强输入验证。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The NUMBER data type stores zero as well as positive正数 and negative负数 fixed numbers withabsolute values绝对值 from 1.0 x 10-130 to but not including 1.0 x 10126. If you specify指定 anarithmetic expression算术表达式 whose value has an absolute value greater较大 than or equal to 1.0 x 10126, then Oracle returns an error. Each每个 NUMBER value requires需要 from 1 to 22 bytes.

Specify指定 a fixed-point number using the following form:

NUMBER(p,s)

where:

  • p is the precision精度, or the maximum number of significant decimal digits有效小数位数, where the most significant digit有效位 is the left-most nonzero digit非零位, andthe least significant digit最低有效位 is the right-most known digit数字. Oracleguarantees保证 the portability of可移植性 numbers with precision精度 of up to 20 base-100 digits, which is equivalent相等的 to 39 or 40 decimal小数 digits depending on theposition of位置 the decimal point.

  • s is the scale标度, or the number of digits from the decimal point to the least significant digit. The scale标度can range from -84 to 127.

    • Positive正数 scale is the number of significant digits有效位 to the right of the decimal point to and including the least significant digit.

    • Negative负数 scale is the number of significant digits to the left of the decimal小数point, to but not including the least significant digit. For negative负数 scale the least significant digit is on the left side左边 of the decimal point, because theactual实际 data is rounded全面 to the specified指定 number of places to the left of the decimal point. For example, a specification规格 of (10,-2) means to round tohundreds百位.

Scale标度 can be greater than precision精度, most commonly通常 when e notation注释 is used. When scale is greater than precision, the precision specifies指定 the maximum number ofsignificant digits有效位 to the right of the decimal point. For example, a column defined定义as NUMBER(4,5) requires需要 a zero for the first digit数字 after the decimal point and rounds all values past the fifth digit过五位数 after the decimal point.

It is good practice练习 to specify指定 the scale and precision精度 of a fixed-point number column for extra integrity额外的完整性 checking on input. Specifying指定 scale and precision does not force all values to a fixed length. If a value exceeds the precision, then Oracle returns an error. If a value exceeds超过 the scale, then Oracle rounds it.

Specify指定 an integer整数 using the following form:

NUMBER(p)

This represents代表 a fixed-point number with precision p and scale 0 and is equivalent相等的to NUMBER(p,0).

Specify指定 a floating-point number using the following form:

NUMBER

The absence没有 of precision and scale designators specifies指定 the maximum range and precision for an Oracle number.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值