CHAR9 scalar function
The CHAR9 function returns a fixed-length character string representation of the argument. The CHAR9 function is intended for compatibility with previous releases of Db2 for z/OS® that depend on the result format that is returned for decimal input values in Version 9 and earlier.
The first argument can be any one value of the following types:
- Integer number
- Decimal number
- Floating-point number
- Decimal floating-point number
- Character string
- Graphic string
- Datetime value
- Row ID value
If the first argument is a decimal number, the result is formatted as indicated in the following description. However, if the first argument is not a decimal number, the result is identical to the result of the CHAR function.
Decimal to Character:
- Decimal to Character
-
- decimal-expression
- An expression that returns a value that is a built-in decimal data type. To specify a different precision and scale for the value of the expression, apply the DECIMAL function before applying the CHAR9 function.
- decimal-character
- Specifies the single-byte character constant (CHAR or VARCHAR) that delimits the decimal digits in the result character string. The character must not be a digit, a plus sign (+), a minus sign (-), or a blank. The default is the period (.) or comma (,). For information about the factors that govern the choice, see Decimal point representation
The result is the fixed-length character string representation of the argument. The result includes a decimal character and up to p digits, where p is the precision of the decimal-expression with the preceding minus sign if the argument is negative. Leading and trailing zeros are returned, and a leading blank is returned for a positive decimal value. The result includes a decimal character even if the scale of decimal-expression is zero. If the number of bytes in the result is less than the defined length of the result, the result is padded on the right with blanks.
The length of the result is 2 +p, where p is the precision of the decimal-expression.
The length attribute of the result is 2+p where p is the precision of decimal-expression.
The actual length of the result is the smallest number of characters that can be used to represent the result, except that trailing zeros are included. If the argument is negative, the result begins with a minus sign. Otherwise, the result begins with a digit. If the scale of decimal-expression is zero, the decimal character is not returned.
The CCSID of the result is determined from the context in which the function was invoked. For more information, see Determining the encoding scheme and CCSID of a string.
Examples
The following table shows the difference between the results of the CHAR and CHAR9 functions for example decimal number arguments.
Decimal argument | CHAR function result | CHAR9 function result |
---|---|---|
(000.1) |
'.1 ' |
' 000.1' |
(1000) |
'1000 ' |
' 1000.' |
(1.1) |
'1.1 ' |
' 1.1' |