Implicit cast from numeric data to string data
When DB2® implicitly casts a numeric value to a string value, the target type is VARCHAR value which is then compatible with other character string or graphic string data types.
The length attribute and the CCSID attribute of the result of the cast are determined in the same way as the VARCHAR function. When GRAPHIC or VARGRAPHIC data types are involved, the encoding scheme must be UNICODE. The following table shows the target type and length:
Source data type | Target data type |
---|---|
SMALLINT | VARCHAR(6) |
INTEGER | VARCHAR(11) |
BIGINT | VARCHAR(20) |
NUMERIC or DECIMAL | VARCHAR(precision+2) |
REAL | VARCHAR(24) |
FLOAT | VARCHAR(24) |
DOUBLE | VARCHAR(24) |
DECFLOAT | VARCHAR(42) |
Implicit conversion from a numeric value to a string value can happen during:
- Assignment (where the source value is a number and the target
operand is a character string or graphic string data type).
Among assignment statements, implicit casting is not supported for the SET statements for special registers, the RETURNS clause and RETURN statement for functions, and the SQL control statements: RETURN, SIGNAL, and RESIGNAL.
- Application of concatenation operators (CONCAT and ||)
- Application
of set operators. Implicit conversion is not supported in the following cases:
- One operand of a set operator is a numeric value and the other operand is a string value
- A numeric value is compared to or assigned to a string value that is the result of a fullselect which included a set operator