Categories:

Konvertierungsfunktionen

TRY_TO_DECFLOAT

A special version of TO_DECFLOAT that performs the same operation (that is, converts an input expression to a DECFLOAT), but with error-handling support. If the conversion can’t be performed, it returns a NULL value instead of raising an error.

For more information, see Konvertierungsfunktionen zur Fehlerbehandlung.

Syntax

TRY_TO_DECFLOAT( <string_expr> [ , '<format>' ] )
Copy

Arguments

Required:

expr

An expression of a numeric, character, or Boolean type.

Optional:

'format'

If the expression evaluates to a string, then the function accepts an optional format model. For more information, see SQL-Formatmodelle. The format model specifies the format of the input string, not the format of the output value.

Usage notes

The special values 'NaN' (not a number), 'inf' (infinity), and '-inf' (negative infinity) aren’t supported.

Returns

This function returns a value of DECFLOAT data type.

If there is a conversion error, the function returns NULL.

Examples

This example uses the TRY_TO_DECFLOAT function:

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

For additional examples, see TO_DECFLOAT.