Hive常用函数

  • Post author:
  • Post category:其他


1、数学函数

(1)round:四舍五入 select round(数值,小数点位数);

(2)ceil:向上取整 select ceil(45.6);

(3)floor:向下取整 select floor(45.6);

2、字符函数

(1)lower:转成小写

select lower(‘Hive’); –hive

(2)upper:转成大写

select lower(‘Hive’); –HIVE

(3)length:长度

select length(‘Hive’); –4

(4)concat:拼接字符串

select concat(‘hello’,’Hive’); –helloHive

(5)substr:求子串

select substr(‘hive’,2); –ive

select substr(‘hive’,2,1); –i

(6)trim:去掉前后的空格

select trim(‘  hive   ‘); -hive

(7)lpad:左填充

对hive填充到10位,补位用#

select lpad(‘hive’,10,’#’); –######hive

(8)rpad:右填充

select rpad(‘hive’,10,’#’); –hive######

5、日期函数

(1)to_date

select to_date(‘2015-06-01 15:34:23’); –2015-06-01

(2)year

select year(‘2015-05-22 15:34:23’); –2015

(3)month

select month(‘2015-05-22 15:34:23’); –5

(4)day

select day(‘2015-05-22 15:34:23’); –22

(5)weekofyear

select weekofyear(‘2015-05-22 15:34:23’); –21

(6)datediff

select datediff(‘2015-05-22 15:34:23′,’2015-05-29 15:34:23’); –[-7]

(7)date_add

select date_add(‘2015-05-22 15:34:23’,2); –2015-05-24

(8)date_sub

select date_sub(‘2015-05-22 15:34:23’,2); –2015-05-20



版权声明:本文为youhuaguo001原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。