NUMBER data type
The NUMBER data type supports applications that use the Oracle NUMBER data type. This capability does not apply to the Entry plan of the Db2® Warehouse SaaS managed service.
Effects
- If you specify NUMBER without precision and scale attributes, it is mapped to DECFLOAT(16).
- If you specify NUMBER(p), it is mapped to DECIMAL(p).
- If you specify NUMBER(p,s), it is mapped to DECIMAL(p,s).
Numeric literal support is unchanged: the rules for integer, decimal, and floating-point constants continue to apply. These rules limit decimal literals to 31 digits and floating-point literals to the range of binary double-precision floating-point values. If necessary, you can use a string-to-DECFLOAT(34) cast, using the CAST specification or the DECFLOAT function, for values beyond the range of DECIMAL or DOUBLE up to the range of DECFLOAT(34). There is currently no support for a numeric literal that ends in either D, representing 64-bit binary floating-point values, or F, representing 32-bit binary floating-point values. A numeric literal that includes an E has the data type of DOUBLE, which you can cast to REAL using the CAST specification or the cast function REAL
If you cast NUMBER data values to character strings, using either the CAST specification or the VARCHAR or CHAR scalar function, all leading zeros are stripped from the result.
The default data type that is used for a sequence value in the CREATE SEQUENCE statement is DECIMAL(27) instead of INTEGER.
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 type of performance also applies to arithmetic operations where
both operands have a DECIMAL or DECFLOAT(16) data type, which differs from the description of
decimal arithmetic in the Expressions with arithmetic operators
section of Expressions. Additionally, all division operations involving only integer data types
(SMALLINT, INTEGER, or BIGINT) are effectively performed using decimal floating-point arithmetic.
These operations 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.
- COALESCE
- DECODE
- GREATEST
- LEAST
- MAX (scalar)
- MIN (scalar)
- NVL
- VALUE
- Corresponding columns in set operations: UNION, EXCEPT(MINUS), and INTERSECT
- Expression values in the IN list of an IN predicate
- Corresponding expressions of a multiple row VALUES clause
| 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 |
In a database with NUMBER support enabled, the built-in functions STDDEV, VAR and VARIANCE with integer input returns DECFLOAT instead of DOUBLE. Any view column or materialized query table (MQT) column with a result type that depends on this function continues to return the old result type until the view or MQT is regenerated or recreated. In the case of an MQT, any queries that previously routed to the MQT will not longer do so until the MQT is recreated.
Client-server compatibility
Client applications working with a database server that you enable for NUMBER data type support never receive a NUMBER data type from the server. Any column or expression that would report NUMBER from an Oracle server report either DECIMAL or DECFLOAT from a database server.
Because an Oracle environment expects the rounding mode to be round-half-up, it is important that the client rounding mode match the server rounding mode. This means that the db2cli.ini file setting must match the value of the decflt_rounding database configuration parameter. To most closely match the Oracle rounding mode, you should specify ROUND_HALF_UP for the database configuration parameter.
Restrictions
- There is no support for the following items:
- A precision attribute greater than 31
- A precision attribute of asterisk (*)
- A scale attribute that exceeds the precision attribute
- A negative scale attribute
- You cannot invoke the trigonometric functions or the DIGITS scalar function with arguments of data type NUMBER without a precision (DECFLOAT).
- You cannot create a distinct type with the name NUMBER.