Datetime to Character
>>-CHAR--(--datetime-expression--+--------------+--)----------->< '-,--+-ISO---+-' +-USA---+ +-EUR---+ +-JIS---+ '-LOCAL-'
Graphic to Character
>>-CHAR--(--graphic-expression--+------------+--)-------------->< '-,--integer-'
Character to Character
>>-CHAR--(--character-expression--+------------+--)------------>< '-,--integer-'
Integer to Character
>>-CHAR--(--integer-expression--)------------------------------><
Decimal to Character
>>-CHAR--(--decimal-expression--+----------------------+--)---->< '-,--decimal-character-'
Floating-point to Character
>>-CHAR---------------------------------------------------------> >--(--floating-point-expression--+----------------------+--)--->< '-,--decimal-character-'
The CHAR function returns a fixed-length character-string representation of:
The first argument must be a built-in data type other than a BINARY, VARBINARY, or BLOB.
The result of the function is a fixed-length character string. If the first argument can be null, the result can be null; if the first argument is null, the result is the null value.
Datetime to Character
The result is the character-string representation of the timestamp. The length of the result is 26.
Graphic to Character
If the second argument is not specified:
The actual length is the same as the length attribute of the result. If the length of the graphic-expression is less than the length of the result, the result is padded with blanks up to the length of the result. If the length of the graphic-expression is greater than the length attribute of the result, truncation is performed. A warning (SQLSTATE 01004) is returned unless the truncated characters were all blanks.
The CCSID of the string is the default CCSID of the current server.
Character to Character
If the second argument is not specified:
The actual length is the same as the length attribute of the result. If the length of the character-expression is less than the length of the result, the result is padded with blanks up to the length of the result. If the length of the character-expression is greater than the length attribute of the result, truncation is performed. A warning (SQLSTATE 01004) is returned unless the truncated characters were all blanks.
The CCSID of the string is the CCSID of the character-expression.
Integer to Character
The result is the fixed-length character-string representation of the argument in the form of an SQL integer constant. The result consists of n characters that are the significant digits that represent the value of the argument with a preceding minus sign if the argument is negative. The result is left justified.
The length of the result is 6. If the number of characters in the result is less than 6, then the result is padded on the right with blanks.
The length of the result is 11. If the number of characters in the result is less than 11, then the result is padded on the right with blanks.
The length of the result is 20. If the number of characters in the result is less than 20, then the result is padded on the right with blanks.
The CCSID of the string is the default SBCS CCSID at the current server.
Decimal to Character
The result is a 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 a preceding minus sign if the argument is negative. Leading zeros are not returned. Trailing zeros are returned.
The length of the result is 2+p where p is the precision of the decimal-expression. This means that a positive value will always include one trailing blank.
The CCSID of the string is the default SBCS CCSID at the current server.
Floating-point to Character
The result is a fixed-length character-string representation of the argument in the form of a floating-point constant. The length of the result is 24. If the argument is negative, the first character of the result is a minus sign. Otherwise, the first character is a digit. If the argument is zero, the result is 0E0. Otherwise, the result includes the smallest number of characters that can be used to represent the value of the argument such that the mantissa consists of a single digit other than zero followed by a period and a sequence of digits.
If the number of characters in the result is less than 24, then the result is padded on the right with blanks.
The CCSID of the string is the default SBCS CCSID at the current server.
Syntax alternatives: When the first argument is numeric, or the first argument is a string and the length argument is specified, the CAST specification should be used for maximal portability. For more information, see CAST specification.
SELECT CHAR(PRSTDATE, USA) FROM PROJECTResults in the value '12/25/1988'.
SELECT CHAR(PRSTDATE) FROM PROJECTResults in the value '12/25/88'.
SELECT CHAR(STARTING, USA) FROM CL_SCHEDResults in the value '5:12 PM'.
SELECT CHAR(STARTING + :HOUR_DUR, JIS) FROM CL_SCHEDResults in the value '10:12:00'.
SELECT CHAR(RECEIVED) FROM IN_TRAYResults in the value '1988-12-25-17.12.30.000000'.
SELECT CHAR(LASTNAME,10) FROM EMPLOYEEFor rows having a LASTNAME with a length greater than 10 characters (excluding trailing blanks), a warning (SQLSTATE 01004) that the value is truncated is returned.
SELECT CHAR(EDLEVEL) FROM EMPLOYEEAn EDLEVEL of 18 would be returned as the CHAR(6) value '18 ' (18 followed by 4 blanks).
SELECT CHAR(20000.25 - SALARY, ',') FROM EMPLOYEEA SALARY of 21150 returns the value '-1149,75 ' (-1149,75 followed by 3 blanks).
SELECT CHAR(:DOUBLE_NUM) FROM SYSIBM.SYSDUMMY1Results in the character value '-9.8765432100000002E-33 '.
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.