Datetime to Varchar
>>-VARCHAR--(--datetime-expression--+--------------+--)-------->< '-,--+-ISO---+-' +-USA---+ +-EUR---+ +-JIS---+ '-LOCAL-'
Character to Varchar
>>-VARCHAR (--character-expression------------------------------> >--+--------------------------------+--)----------------------->< '-,--+-length--+--+------------+-' '-DEFAULT-' '-,--integer-'
Graphic to Varchar
>>-VARCHAR (--graphic-expression--------------------------------> >--+--------------------------------+--)----------------------->< '-,--+-length--+--+------------+-' '-DEFAULT-' '-,--integer-'
Integer to Varchar
>>-VARCHAR--(--integer-expression--)---------------------------><
Decimal to Varchar
>>-VARCHAR------------------------------------------------------> >--(--decimal-expression--+----------------------+--)---------->< '-,--decimal-character-'
Floating-point to Varchar
>>-VARCHAR------------------------------------------------------> >--(--floating-point-expression--+----------------------+--)--->< '-,--decimal-character-'
The VARCHAR function returns a character-string representation of:
The result of the function is a varying-length 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 attribute and actual length of the result is 26.
Character to Varchar
If the second argument is not specified or DEFAULT is specified:
The actual length of the result is the minimum of the length attribute of the result and the actual length of character-expression. 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.
If the third argument is not specified then:
Graphic to Varchar
If the second argument is not specified or DEFAULT is specified, the length attribute of the result is determined as follows (where n is the length attribute of the first argument):
The actual length of the result is the minimum of the length attribute of the result and the actual length of graphic-expression. 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.
If the third argument is not specified, the CCSID of the result is the default CCSID at the current server. If the default CCSID is mixed data, then the result is mixed data. If the default CCSID is SBCS data, then the result is SBCS data.
Integer to Varchar
The result is a varying-length character string 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. It is left justified.
The actual length of the result is the smallest number of characters that can be used to represent the value of the argument. Leading zeroes are not included. If the argument is negative, the first character of the result is a minus sign. Otherwise, the first character is a digit.
The CCSID of the result is the default SBCS CCSID at the current server.
Decimal to Varchar
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 the decimal-expression with a preceding minus sign if the argument is negative. Leading zeros are not returned. Trailing zeros are returned.
The length attribute of the result is 2+p where p is the precision of the 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 characters are included. Leading zeros are not included. If the argument is negative, the result begins with a minus sign. Otherwise, the result begins with a digit.
The CCSID of the result is the default SBCS CCSID at the current server.
Floating-point to Varchar
The result is a varying-length character string representation of the argument in the form of a floating-point constant.
The length attribute of the result is 24. The actual length of the result is the smallest number of characters that can represent the value of the argument such that the mantissa consists of a single digit other than zero followed by the decimal-character and a sequence of digits. 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.
The CCSID of the result is the default SBCS CCSID at the current server.
Syntax alternatives: If the length attribute is specified, the CAST specification should be used for maximal portability. For more information, see CAST specification.
SELECT VARCHAR(EMPNO,10) INTO :VARHV FROM EMPLOYEE
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.