- Categories:
TRY_CAST¶
A special version of CAST , :: that is available for a subset of data type conversions. It performs the same operation (i.e. converts a value of one data type into another data type), but returns a NULL value instead of raising an error when the conversion can not be performed.
For more information, see Error-handling conversion functions.
Syntax¶
Usage notes¶
Only works for string expressions.
target_data_typemust be one of the following:VARCHAR (or any of its synonyms)
NUMBER (or any of its synonyms)
DOUBLE
BOOLEAN
DATE
TIME
TIMESTAMP, TIMESTAMP_LTZ, TIMESTAMP_NTZ, or TIMESTAMP_TZ
Examples¶
The following code samples show how to use the TRY_CAST function with
valid and invalid values: