The VARCHAR function converts a fixed or variable-length character string into a variable-length character string.

The arguments are defined as follows:
| stringExpression is a fixed or variable-length character string. If stringExpression length exceeds its maximum length, the product generates an error message and terminates the unit of work (UOW). length is an integer constant of the maximum length of the result. If the value of length is shorter than the length of stringExpression, then the function truncates the result to the specified length, without warning. |
| datetimeExpression must be an expression that is one of the following built-in data types, and the result is the varying length character string representation of these data types: The expression is converted to an external format using the format template, if applicable. You must define the format as follows: | Expression type | Format type | | DATE | The result is a varying-length character string representation of the date. Its format comes from the DATE precompiler option (if specified) or from the DATE FORMAT field on installation panel DSNTIP4. By default, the result has a length attribute and actual length of 10. If the format is LOCAL, the LOCAL DATE LENGTH field on installation panel DSNTIP4 determines the result length. Otherwise, the result length is 10. | | TIME | The result is a varying-length character string representation of the time. Its format comes from the TIME precompiler option (if specified) or from the TIME FORMAT field on installation panel DSNTIP4. If the format is LOCAL, the LOCAL TIME LENGTH field on panel DSNTIP4 determines the result length. Otherwise, the result length is 8. | | TIMESTAMP WITHOUT TIMEZONE | The result is the character string representation of the timestamp. If datetimeExpression is a TIMESTAMP(0) value, the length of the result is 19. If datetimeExpression is a TIMESTAMP(integer) value, the length of the result is 20+ integer. Otherwise, the result length is 26. The second argument of string may be specified with timestamp(6) as a formatting template that has date/time/microseconds elements. Valid values are: - MM for month
- DD for day
- YY or YYYY for year
- HH for hour
- MM for minute
- SS for second
- XM for AM or PM
- NN for hundredths of a second
- NNNN for milli-second
- NNNNNN for a microsecond.
| | TIMEZONE WITH TIMEZONE | The result is the character string representation of the timestamp with time zone, formatted as yyyy-mm-ddhh.mm.ss.nnnnnn±th:tm with the appropriate number of n characters for the precision of the timestamp. If datetimeExpression is a TIMESTAMP (0) with timezone, the result length is 25. If datetimeExpression is a TIMESTAMP(integer) with timezone, the length of the result is 26+ integer. The second argument must not be specified. |
|
WarningImportant
If the argument can be null, the result can be null; if argument value is null, the result is the null value.