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

preview_player
Показать описание
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
Рекомендации по теме
Комментарии
Автор

hi bro, in my system time is showing current date but when i execute current_date() in snowflake it is showing yesterday date, please suggest me

anjaneyulugodduvelagala
Автор

Cast(2021-04-05 as varchar) is not converting numbers to varchar. Pls tell y?

natarajbeelagi
Автор

Please make a video on try_cast as well..

yadavsachin
Автор

Bro..Post some videos on snowpro certification

Hema-ymqi
Автор

what is difference between cast and TRY_CAST?

bnmkrishan
join shbcf.ru