NUMBER Datatype
The NUMBER datatype stores zero as well as positive and negative fixed numbers with absolute values from 1.0 x 10-130 to (but not including) 1.0 x 10126. If you specify an arithmetic 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:
-
pis the precision, or the total number of significant decimal digits, where the most significant digit is the left-most nonzero digit, and the least significant digit is the right-most known digit. Oracle guarantees the portability of numbers with precision of up to 20 base-100 digits, which is equivalent to 39 or 40 decimal digits depending on the position of the decimal point. -
sis 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 the actual 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 to hundreds.
-
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 of significant 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.
See Also:
"Floating-Point Numbers"Table 2-2 show how Oracle stores data using different precisions and scales.
Table 2-2 Storage of Scale and Precision
| Actual Data | Specified As | Stored As |
|---|---|---|
| 123.89 |
| 123.89 |
| 123.89 |
| 124 |
| 123.89 |
| 123.89 |
| 123.89 |
| 123.9 |
| 123.89 |
| exceeds precision |
| 123.89 |
| exceeds precision |
| 123.89 |
| 100 |
| .01234 |
| .01234 |
| .00012 |
| .00012 |
| .000127 |
| .00013 |
| .0000012 |
| .0000012 |
| .00000123 |
| .0000012 |
| 1.2e-4 |
| 0.00012 |
| 1.2e-5 |
| 0.00001 |

本文详细介绍了Oracle数据库中NUMBER数据类型的使用方法,包括其存储范围、精度和小数位数的指定方式。NUMBER类型可以存储从1.0×10^-130到接近但不包括1.0×10^126之间的数值。文章还解释了如何定义固定点数、整数及浮点数,并提供了多个示例说明不同精度和小数位数设置下数据的存储形式。
850

被折叠的 条评论
为什么被折叠?



