TO_VARCHAR
functionsupportedCore SQL functionsConverts the input expression to a string. For NULL input, the output is NULL. These functions are synonymous.
Syntax
supportedpartialnot supportednot scored
TO_CHAR( <expr> )
TO_CHAR( <numeric_expr> [, '<format>' ] )
TO_CHAR( <date_or_time_expr> [, '<format>' ] )
TO_CHAR( <binary_expr> [, '<format>' ] )
TO_VARCHAR( <expr> )
TO_VARCHAR( <numeric_expr> [, '<format>' ] )
TO_VARCHAR( <date_or_time_expr> [, '<format>' ] )
TO_VARCHAR( <binary_expr> [, '<format>' ] )
Parameters
| Name | Required | Description |
|---|---|---|
expr | required | An expression of any data type. |
numeric_expr | required | A numeric expression. |
date_or_time_expr | required | An expression of type DATE, TIME, or TIMESTAMP. |
binary_expr | required | An expression of type BINARY or VARBINARY. |
format | optional | The format of the output string: For numeric_expr, specifies the SQL format model used to interpret the numeric expression. For more information, see SQL format models. For date_or_time_expr, specifies the expected format to parse or produce a string. For more information, see Date and time formats in conversion functions. The default is the current value of the following session parameters: DATE_OUTPUT_FORMAT (for DATE inputs) TIME_OUTPUT_FORMAT (for TIME inputs) TIMESTAMP_OUTPUT_FORMAT (for TIMESTAMP inputs) For binary_expr, specifies the format in which to produce the string (e.g. ‘HEX’, ‘BASE64’ or ‘UTF-8’). For more information, see Overview of supported binary formats. |
Returns
This function returns a value of VARCHAR data type or NULL.
Usage notes
- For VARIANT, ARRAY, or OBJECT inputs, the output is the string containing a JSON document or JSON elementary value (unless VARIANT or OBJECT contains an XML tag, in which case the output is a string containing an XML document): A string stored in VARIANT is preserved as is (i.e. it is not converted to a JSON string).
- A JSON null value is converted to a string containing the word “null”.