Hive中CAST()函数用法
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Hive中CAST()函数用法相关的知识,希望对你有一定的参考价值。
参考技术A Cast(字段名 as 转换的类型 ),其中类型可以为:CHAR[(N)] 字符型
DATE 日期型
DATETIME 日期和时间型
DECIMAL float型
SIGNED int
TIME 时间型
例如表table1
date
2015-11-03 15:31:26
select cast(date as signed) as date from table1;
结果如下:
date
20151103153126
select cast(date as char) as date from table1;
结果如下:
date
2015-11-03 15:31:26
select cast(date as datetime) as date from table1;
结果如下:
date
2015-11-03 15:31:26
select cast(date as date) as date from table1;
结果如下:
date
2015-11-03
select cast(date as time) as date from table1;
结果如下:
date
15:31:26
这里date对应日期,time对应时间
Hive函数用法:Cast(字段名 as 转换的类型 )
Cast(字段名 as 转换的类型 ),其中类型可以为:
- CHAR[(N)] 字符型
- DATE 日期型
- DATETIME 日期和时间型
- DECIMAL float型
- SIGNED int
- TIME 时间型
例子
select cast(date as signed) as date from table1;
-- 结果如下:
date
20151103153126
select cast(date as char) as date from table1;
-- 结果如下:
date
2015-11-03 15:31:26
select cast(date as datetime) as date from table1;
-- 结果如下:
date
2015-11-03 15:31:26
select cast(date as date) as date from table1;
--结果如下:
date
2015-11-03
select cast(date as time) as date from table1;
-- 结果如下:
date
15:31:26
这里date对应日期,time对应时间
以上是关于Hive中CAST()函数用法的主要内容,如果未能解决你的问题,请参考以下文章