Numeric types consist of four-byte integers, four-byte and eight-byte floating-point numbers, and fixed-precision decimals.
The following table lists the available types.
|BINARY INTEGER||4 bytes||Signed integer, Alias for INTEGER||-2,147,483,648 to +2,147,483,647|
|DOUBLE PRECISION||8 bytes||Variable-precision, inexact||15 decimal digits precision|
|INTEGER||4 bytes||Usual choice for integer||-2,147,483,648 to +2,147,483,647|
|NUMBER||Variable||User-specified precision, exact||Up to 1000 digits of precision|
|NUMBER(p [, s ] )||Variable||Exact numeric of maximum precision, p, and optional scale, s||Up to 1000 digits of precision|
|PLS INTEGER||4 bytes||Signed integer, Alias for INTEGER||-2,147,483,648 to +2,147,483,647|
|REAL||4 bytes||Variable-precision, inexact||6 decimal digits precision|
|ROWID||4 bytes||Signed 4 bit integer.||0 to 4,294,967,295|
The following sections describe the types in details.
The INTEGER type stores whole numbers without fractional components between the values of -2,147,483,648 and +2,147,483,647. Attempts to store values outside of the allowed range will result in an error.
Columns of the ROWID type holds fixed-length binary data that describes the physical address of a record. ROWID is an unsigned, four-byte INTEGER that stores whole numbers without fractional components between the values of 0 and 4,294,967,295. Attempts to store values outside of the allowed range will result in an error.
Arbitrary precision number
The NUMBER type can store practically an unlimited number of digits of precision and perform calculations exactly. It is recommended for storing monetary amounts and other quantities where exactness is required. However, the NUMBER type is very slow compared to the floating-point types described in the next section.
The scale of a NUMBER is the count of decimal digits in the fractional part, to the right of the decimal point. The precision of a NUMBER is the total count of significant digits in the whole number, that is, the number of digits to both sides of the decimal point. So the number 23.5141 has a precision of 6 and a scale of 4. Integers can be considered to have a scale of zero.
Both the precision and the scale of the NUMBER type can be configured. You can use the following syntax to declare a column of type NUMBER:
The precision must be positive, the scale zero or positive. The following syntax
selects a scale of 0. Specifying NUMBER without any precision or scale creates a column in which numeric values of any precision and scale can be stored, up to the implementation limit on precision. A column of this kind will not coerce input values to any particular scale, whereas NUMBER columns with a declared scale will coerce input values to that scale. The SQL standard requires a default scale of 0, for example, coercion to integer precision. For maximum portability, it is best to specify the precision and scale explicitly.
If the precision or scale of a value is greater than the declared precision or scale of a column, the system will attempt to round the value. If the value cannot be rounded to satisfy the declared limits, an error is raised.
The REAL and DOUBLE PRECISION data types are inexact, variable-precision numeric types. In practice, these types are usually implementations of IEEE Standard 754 for Binary Floating-Point Arithmetic (single and double precision, respectively), to the extent that the underlying processor, operating system, and compiler support it.
Inexact means that some values cannot be converted exactly to the internal format and are stored as approximations,
so that storing and printing back out a value may show slight discrepancies. Managing these errors and how they propagate through calculations is the subject of an entire branch of mathematics and computer science and will not be discussed further here, except for the following points:
If you require exact storage and calculations such as for monetary amounts, use the NUMBER type instead.
If you want to do complicated calculations by using these types for anything important, especially if you rely on certain behavior in boundary cases such as infinity and underflow, you must evaluate the implementation carefully.
Comparing two floating-point values for equality may or may not work as expected. On most platforms, the REAL type has a range of at least 1E-37 to 1E+37 with a precision of at least 6 decimal digits. The DOUBLE PRECISION type typically has a range of around 1E-307 to 1E+308 with a precision of at least 15 digits. Values that are too large or too small will cause an error. Rounding may take place if the precision of an input number is too high. Numbers too close to zero that are not representable as distinct from zero will cause an underflow error.
PolarDB for Oracle also supports the SQL standard notations FLOAT and FLOAT(p) for specifying inexact numeric types. Here, p specifies the minimum acceptable precision in binary digits. PolarDB for Oracle accepts FLOAT(1) to FLOAT(24) as selecting the REAL type, while FLOAT(25) to FLOAT(53) as selecting DOUBLE PRECISION. Values of p that exceed the allowed range draw an error. FLOAT with no precision specified is taken as DOUBLE PRECISION type.