Categories:
Conversion Functions

TRY_TO_DOUBLE

A special version of TO_DOUBLE that performs the same operation (i.e. converts an input expression to a double-precision floating-point number), but with error-handling support (i.e. if the conversion cannot be performed, it returns a NULL value instead of raising an error).

For more information, see Error-handling Conversion Functions.

Syntax

TRY_TO_DOUBLE( <string_expr> )

Usage Notes

  • Only works for string expressions.

Examples

This demonstrates usage of TRY_TO_DOUBLE:

SELECT TRY_TO_DOUBLE('3.1415926'), TRY_TO_DOUBLE('Invalid');
+----------------------------+--------------------------+
| TRY_TO_DOUBLE('3.1415926') | TRY_TO_DOUBLE('INVALID') |
|----------------------------+--------------------------|
|                  3.1415926 |                     NULL |
+----------------------------+--------------------------+