A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.snowflake.com/en/sql-reference/functions/try_cast below:

Website Navigation


TRY_CAST | Snowflake Documentation

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
TRY_CAST( <source_string_expr> AS <target_data_type> )

Copy

Usage notes Examples

The following code samples show how to use the TRY_CAST function with valid and invalid values:

SELECT TRY_CAST('05-Mar-2016' AS TIMESTAMP);
+--------------------------------------+
| TRY_CAST('05-MAR-2016' AS TIMESTAMP) |
|--------------------------------------|
| 2016-03-05 00:00:00.000              |
+--------------------------------------+

Copy

SELECT TRY_CAST('05/16' AS TIMESTAMP);
+--------------------------------+
| TRY_CAST('05/16' AS TIMESTAMP) |
|--------------------------------|
| NULL                           |
+--------------------------------+

Copy

SELECT TRY_CAST('ABCD' AS CHAR(2));
+-----------------------------+
| TRY_CAST('ABCD' AS CHAR(2)) |
|-----------------------------|
| NULL                        |
+-----------------------------+

Copy

SELECT TRY_CAST('ABCD' AS VARCHAR(10));
+---------------------------------+
| TRY_CAST('ABCD' AS VARCHAR(10)) |
|---------------------------------|
| ABCD                            |
+---------------------------------+

Copy


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4