filmov
tv
6. CAST Conversion Function - Scalar Functions|SNOWFLAKE SQL Function Reference|Snowflake|VCKLY Tech

Показать описание
In this video , I am going to talk about CAST Conversion Function.
What is the CAST Conversion Function?
Converts a value of one data type into another data type.
CAST conversion function comes under Any Data Type Conversion Function
The semantics of CAST are the same as the semantics of the corresponding TO_ datatype conversion functions.
If the cast is not possible, an error is raised.
The :: operator provides alternative syntax for CAST.
Usage Notes:
If the scale is not sufficient to hold the input value, the function rounds the value.
If the precision is not sufficient to hold the input value, the function raises an error.
--Convert a string containing a number to a decimal with specified scale (2):
SELECT CAST('12.17' as decimal(4,2) );
--If the scale is not sufficient to hold the input value, the function rounds the value.
SELECT CAST('12.127456' as decimal(4,2) );
--If the precision is not sufficient to hold the input value, the function raises an error.
SELECT CAST('123.12' as number(4,2) );
SELECT CAST('123.12' as number(5,2) );
--Convert the same string to a decimal with scale 5, using the :: notation:
SELECT '1.12345':: decimal(10,5);
--Convert a number to an integer:
select cast(1.79 as integer);
select cast(1.29 as integer);
--Convert a string containing a date to a timestamp:
select current_date();
select current_timestamp();
select cast('05-Mar-2021' as timestamp);
select cast('05-Mar-2021' as date);
#Snowflake#DataCloud#SnowflakeDataWarehouse#vcklytech#DataCloud
What is the CAST Conversion Function?
Converts a value of one data type into another data type.
CAST conversion function comes under Any Data Type Conversion Function
The semantics of CAST are the same as the semantics of the corresponding TO_ datatype conversion functions.
If the cast is not possible, an error is raised.
The :: operator provides alternative syntax for CAST.
Usage Notes:
If the scale is not sufficient to hold the input value, the function rounds the value.
If the precision is not sufficient to hold the input value, the function raises an error.
--Convert a string containing a number to a decimal with specified scale (2):
SELECT CAST('12.17' as decimal(4,2) );
--If the scale is not sufficient to hold the input value, the function rounds the value.
SELECT CAST('12.127456' as decimal(4,2) );
--If the precision is not sufficient to hold the input value, the function raises an error.
SELECT CAST('123.12' as number(4,2) );
SELECT CAST('123.12' as number(5,2) );
--Convert the same string to a decimal with scale 5, using the :: notation:
SELECT '1.12345':: decimal(10,5);
--Convert a number to an integer:
select cast(1.79 as integer);
select cast(1.29 as integer);
--Convert a string containing a date to a timestamp:
select current_date();
select current_timestamp();
select cast('05-Mar-2021' as timestamp);
select cast('05-Mar-2021' as date);
#Snowflake#DataCloud#SnowflakeDataWarehouse#vcklytech#DataCloud
Комментарии