Numeric Types v13

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:

NameStorage SizeDescriptionRange
BINARY_INTEGER4 bytesSigned integer, Alias for INTEGER-2,147,483,648 to +2,147,483,647
DOUBLE PRECISION8 bytesVariable-precision, inexact15 decimal digits precision
INTEGER4 bytesUsual choice for integer-2,147,483,648 to +2,147,483,647
NUMBERVariableUser-specified precision, exactUp to 1000 digits of precision
NUMBER(p [, s ] )VariableExact numeric of maximum precision, p, and optional scale, sUp to 1000 digits of precision
PLS_INTEGER4 bytesSigned integer, Alias for INTEGER-2,147,483,648 to +2,147,483,647
REAL4 bytesVariable-precision, inexact6 decimal digits precision
ROWID8 bytesSigned 8 bit integer.-9223372036854775808 to 9223372036854775807

The following sections describe the types in detail.

Integer Types

The BINARY_INTEGER, INTEGER, PLS_INTEGER, and ROWID types store whole numbers (without fractional components) as specified in table Numeric Types. Attempts to store values outside of the allowed range will result in an error.

Arbitrary Precision Numbers

The type, NUMBER, can store practically an unlimited number of digits of precision and perform calculations exactly. It is especially 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.

In what follows we use these terms: 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. To declare a column of type NUMBER use the syntax

NUMBER(precision, scale)

The precision must be positive, the scale zero or positive. Alternatively,

NUMBER(precision)

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, i.e., 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 so as to satisfy the declared limits, an error is raised.

Floating-Point Types

The data types REAL and DOUBLE PRECISION 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 with these types for anything important, especially if you rely on certain behavior in boundary cases (infinity, underflow), you should 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.

Advanced Server 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. Advanced Server accepts FLOAT(1) to FLOAT(24) as selecting the REAL type, while FLOAT(25) to FLOAT(53) as selecting DOUBLE PRECISION. Values of p outside the allowed range draw an error. FLOAT with no precision specified is taken to mean DOUBLE PRECISION.