The NUMBER data type is introduced to support applications that use the Oracle NUMBER data type.
Support for NUMBER is at the database level, and must be enabled before creating the database where support is required. This is achieved by setting the DB2_COMPATIBILITY_VECTOR registry variable to the appropriate value. When a database is created with NUMBER enabled, the database configuration parameter number_compat is set to ON. After a database is created with NUMBER support enabled, it cannot be disabled for that database, even if the DB2_COMPATIBILITY_VECTOR registry variable is reset. Similarly, all databases created without NUMBER support enabled cannot have NUMBER support enabled, even by setting the DB2_COMPATIBILITY_VECTOR registry variable.
NUMBER data type support is enabled by setting bit position number 5 (0x10) of the DB2_COMPATIBILITY_VECTOR registry variable before creating a database. To take full advantage of these DB2® compatibility features, set the value to ORA. This is the recommended setting. A new setting for the registry variable does not take effect until after the instance has been stopped and then restarted.
The following support is enabled for a DB2 database that has the number_compat database configuration parameter set to ON.
The maximum supported precision is 31, and the scale must be a positive value no greater than the precision. As a result of this implicit mapping, messages will refer to data types DECFLOAT and DECIMAL instead of NUMBER, and any operations that describe data types for columns or routines will return either DECIMAL or DECFLOAT instead of NUMBER. Note that DECFLOAT(16) provides a lower maximum precision than the Oracle NUMBER data type. If more than 16 digits of precision are needed for storing numbers in tables, the columns with this requirement should be defined explicitly as DECFLOAT(34).
Numeric literal support is unchanged in a DB2 database that has the number_compat configuration parameter set to ON. The rules for integer, decimal, and floating-point constants continue to apply. This limits decimal literals to 31 digits and floating-point literals to the range of binary double-precision floating-point values. A string to DECFLOAT(34) cast (using the CAST specification or the DECFLOAT function) can be used for values beyond the ranges of DECIMAL or DOUBLE up to the range of DECFLOAT(34).
When NUMBER data values are cast to character strings (using either the CAST specification or the VARCHAR or CHAR scalar function), all leading zeros are stripped from the result.
There is currently no support for a numeric literal that ends in either D or F, representing 64-bit binary floating-point and 32-bit binary floating-point values, respectively. A numeric literal that includes an E has the data type of DOUBLE and can be cast to REAL using the CAST specification or the cast function REAL.
In a DB2 database that has the number_compat configuration parameter set to ON, the default data type that is used for a sequence value in the CREATE SEQUENCE statement is DECIMAL(27) instead of INTEGER.
In a DB2 database that has the number_compat configuration parameter set to ON, all arithmetic operations and arithmetic or mathematical functions involving DECIMAL or DECFLOAT data types are effectively performed using decimal floating-point arithmetic and return a value with a data type of DECFLOAT(34). This also applies to arithmetic operations where both operands have DECIMAL or DECFLOAT(16) data types, which differs from the description of decimal arithmetic in the DB2 SQL Reference. (See "Expressions with arithmetic operators" in "Expressions".) Additionally, all division operations involving only integer data types (SMALLINT, INTEGER, or BIGINT) are effectively performed using decimal floating-point arithmetic and return a value with a data type of DECFLOAT(34) instead of an integer data type (division by zero with integer operands returns infinity and a warning instead of an error).
Function resolution is also changed, such that an argument of data type DECIMAL is considered to be a DECFLOAT value during the resolution process. For purposes of function resolution, this effectively treats functions with arguments that correspond to the NUMBER(p[,s]) data type as if the argument data type were NUMBER.
Source Data Type | Target Data Type | |||
---|---|---|---|---|
integer types | DECIMAL | DECFLOAT | REAL/DOUBLE | |
integer types | not applicable | not applicable | decflt_rounding | round_half_even |
DECIMAL | decflt_rounding | decflt_rounding | decflt_rounding | round_half_even |
DECFLOAT | decflt_rounding | decflt_rounding | decflt_rounding | round_half_even |
REAL/DOUBLE | truncate | decflt_rounding | decflt_rounding | round_half_even |
string (cast only) | not applicable | decflt_rounding | decflt_rounding | round_half_even |
The DB2 decimal floating-point values are based on the IEEE 754R standard. Retrieval of DECFLOAT data and casting of DECFLOAT data to character strings removes any trailing zeros after the decimal point.