TRY_TO_DECIMAL
functionsupportedCore SQL functionsA special version of TO_DECIMAL , TO_NUMBER , TO_NUMERIC that performs the same operation of converting an input expression to a fixed-point number, but has error-handling support so that the function returns NULL if the conversion can’t be performed. These functions are synonymous. For more information, see Error-handling conversion functions.
Syntax
supportedpartialnot supportednot scored
TRY_TO_DECIMAL( <string_expr> [, '<format>' ] [, <precision> [, <scale> ] ] )
TRY_TO_NUMBER( <string_expr> [, '<format>' ] [, <precision> [, <scale> ] ] )
TRY_TO_NUMERIC( <string_expr> [, '<format>' ] [, <precision> [, <scale> ] ] )
Parameters
| Name | Required | Description |
|---|---|---|
string_expr | required | An expression of type VARCHAR. |
format | optional | The SQL format model used to parse the input expr and return. For more information, see SQL format models. |
precision | optional | The maximal number of decimal digits in the resulting number; from 1 to 38. In Snowflake, precision is not used to determine the number of bytes that are needed to store the number and doesn’t have any effect on efficiency, so the default is the maximum (38). |
scale | optional | The number of fractional decimal digits (from 0 to precision - 1). 0 indicates no fractional digits (i.e. an integer number). The default scale is 0. |
Returns
The function returns a value of type NUMBER with the following defaults: - If the precision isn’t specified, then it defaults to 38. - If the scale isn’t specified, then it defaults to 0. If the conversion can’t be performed or the input is NULL, returns NULL.
Usage notes
- The input must be a string expression.