DB2 Scalar functions - CHAR
The CHAR function returns a fixed-length character string representation of a value of a different data type.
The schema is SYSIBM. The function name cannot be specified as a qualified name when keywords are used in the function signature. The SYSFUN.CHAR (floating-point-expression) signature continues to be available. In this case, the decimal character is locale sensitive, and therefore returns either a period or a comma, depending on the locale of the database server.
The result is a fixed-length character string representation of integer-expression in the form of an SQL integer constant. The result consists of n characters, which represent the significant digits in the argument, and is preceded by a minus sign if the argument is negative. The result is left-aligned. If the data type of the first argument is:
The code page of the result is the code page of the section.
The result is a fixed-length character string representation of decimal-expression in the form of an SQL decimal constant. The length of the result is 2+p, where p is the precision of decimal-expression. Leading zeros are not included. Trailing zeros are included. If decimal-expression is negative, the first character of the result is a minus sign; otherwise, the first character is a digit or the decimal character. If the scale of decimal-expression is zero, the decimal character is not returned. 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 single-byte blanks.
The result is a fixed-length character string representation of floating-point-expression in the form of an SQL floating-point constant. The length of the result is 24. The result is the smallest number of characters that can represent the value of floating-point-expression such that the mantissa consists of a single digit other than zero followed by a period and a sequence of digits. If floating-point-expression is negative, the first character of the result is a minus sign; otherwise, the first character is a digit. If floating-point-expression is zero, the result is 0E0. If the number of bytes in the result is less than 24, the result is padded on the right with single-byte blanks.
The result is a fixed-length character string representation of decimal-floating-point-expression in the form of an SQL decimal floating-point constant. The length attribute of the result is 42. The result is the smallest number of characters that can represent the value of decimal-floating-point-expression. If decimal-floating-point-expression is negative, the first character of the result is a minus sign; otherwise, the first character is a digit. If decimal-floating-point-expression is zero, the result is 0.
If the value of decimal-floating-point-expression is the special value Infinity, sNaN, or NaN, the strings 'INFINITY', 'SNAN', and 'NAN', respectively, are returned. If the special value is negative, the first character of the result is a minus sign. The decimal floating-point special value sNaN does not result in warning when converted to a string. If the number of characters in the result is less than 42, the result is padded on the right with single-byte blanks.
If the second argument is not specified:
The result is a fixed-length character string. If character-expression is FOR BIT DATA, the result is FOR BIT DATA.
The length of the result is the same as the length attribute of the result. If the length of character-expression is:
The result is a fixed-length character string that is converted from graphic-expression. The length of the result is the same as the length attribute of the result.
If the length of graphic-expression that is converted to a character string is:
The result is a fixed-length FOR BIT DATA character string, padded with blanks if necessary.
The CHAR function returns a fixed-length character string representation of:
In a non-Unicode database, the string units of the result is OCTETS. Otherwise, the string units of the result are determined by the data type of the first argument.
In a Unicode database, when the output string is truncated part-way through a multiple-byte character:
Do not rely on either of these behaviors because they might change in a future release.
If the first argument can be null, the result can be null. If the first argument is null, the result is the null value.
CHAR(PRSTDATE, USA)
CHAR(STARTING, USA)
CHAR(STARTING + :HOUR_DUR, USA)
CHAR(RECEIVED)
SELECT CHAR(LASTNAME,10) FROM EMPLOYEE
SELECT CHAR(EDLEVEL) FROM EMPLOYEE
CHAR(SALARY, ',')
CHAR(20000.25 - SALARY)
CHAR(DECIMAL(:SEASONS_TICKETS,7,2))
CHAR(:DOUBLE_NUM)
values CHAR(3=3)
values CHAR(3>3)