This topic contains the following topics:
The following SQL data types store numeric data:
NUMBER
BINARY_FLOAT
BINARY_DOUBLE
Use the NUMBER data type to store integers and real numbers in a fixed-point or floating-point format. Numbers using this data type are guaranteed to be portable among different Oracle Database platforms. For nearly all cases where you need to store numeric data, you would use the NUMBER data type.
Oracle Database provides the numeric BINARY_FLOAT and BINARY_DOUBLE data types exclusively for floating-point numbers. They support all of the basic functionality provided by the NUMBER data type. However, while NUMBER uses decimal precision, BINARY_FLOAT and BINARY_DOUBLE use binary precision. This enables faster arithmetic calculations and usually reduces storage requirements.
|
See Also:
|
The NUMBER data type 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.
When you specify a fixed-point number use the following form to specify the precision and scale of the number:
NUMBER(precision, scale)
Precision and scale are defined as follows:
Precision is 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. For examples, see Table: Storage of Scale and Precision.
Scale is the number of digits from the decimal point to the least significant digit. The scale can range from -84 to 127. For examples, see Table: Storage of Scale and Precision.
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.
Table: Storage of Scale and Precision show how Oracle stores data using different values for precision and scale.
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 |
The BINARY_FLOAT and BINARY_DOUBLE data types store floating-point data in the 32-bit IEEE 754 format and the double precision 64-bit IEEE 754 format respectively. Compared to the Oracle NUMBER data type, arithmetic operations on floating-point data are usually faster for BINARY_FLOAT and BINARY_DOUBLE. Also, high-precision values require less space when stored as BINARY_FLOAT and BINARY_DOUBLE.
The floating-point number system is a common way of representing and manipulating numeric values in computer systems. The value 4.32682E-21F is an example of a BINARY_FLOAT data type.
Floating-point numbers can have a decimal point anywhere from the first to the last digit or can have no decimal point at all. An exponent may optionally be used following the number to increase the range (for example, 1.777 e-20). A scale value is not applicable to floating-point numbers, because the number of digits that can appear after the decimal point is not restricted.
Binary floating-point numbers differ from NUMBER in the way the values are stored internally by Oracle Database. Values are stored using decimal precision for NUMBER. All literals that are within the range and precision supported by NUMBER are stored exactly as NUMBER. Literals are stored exactly because literals are expressed using decimal precision (the digits 0 through 9). Binary floating-point numbers are stored using binary precision (the digits 0 and 1). Such a storage scheme cannot represent all values using decimal precision exactly. Frequently, the error that occurs when converting a value from decimal to binary precision is undone when the value is converted back from binary to decimal precision. The literal 0.1 is such an example.
BINARY_FLOAT is a 32-bit, single-precision floating-point number data type. Each BINARY_FLOAT value requires 5 bytes, including a length byte.
BINARY_DOUBLE is a 64-bit, double-precision floating-point number data type. Each BINARY_DOUBLE value requires 9 bytes, including a length byte.
In a NUMBER column, floating point numbers have decimal precision. In a BINARY_FLOAT or BINARY_DOUBLE column, floating-point numbers have binary precision. The binary floating-point numbers support the special values infinity and NaN (not a number).
You can specify floating-point numbers within the limits listed in Table: Floating Point Number Limits.