VARCHAR9 scalar function

The VARCHAR9 function returns a fixed-length character string representation of the argument. The VARCHAR9 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.

Important: For portable applications that might run on platforms other than Db2 for z/OS, use the VARCHAR function instead. Other Db2 family products do not support the VARCHAR9 function.

The first argument can be any value of the of the following types:

  • Integer number
  • Decimal number
  • 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 VARCHAR function.

Decimal to Varchar:

Read syntax diagramSkip visual syntax diagramVARCHAR9( decimal-expression,decimal-character)
Decimal to Varchar
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 expression's value, apply the DECIMAL function to the expression before applying the VARCHAR9 function.
decimal-character
Specifies the single-byte character constant (CHAR or VARCHAR) that is used to delimit 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 a varying-length character string representation of the argument. The result includes a decimal character and up to p digits where p is the precision of decimal-expression with a preceding minus sign if the argument is negative. Leading and trailing zeros are returned. The result includes a decimal character even if the scale of decimal-expression is zero.

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 VARCHAR and VARCHAR9 functions for example decimal number arguments.

Table 1. Example results of VARCHAR and VARCHAR9 functions
Decimal Argument VARCHAR Function Result VARCHAR9 Function Result
(000.1) '.1' '0.1'
(1000.) '1000' '1000. '
(1.1) '1.1' '1.1'