hive常用的函数(待补充)

1、解析URL字符串的: parse_url

用法:

select parse_url("",[HOST,PATH,QUERY,REF,PROTOCOL,FILE,AUTHORITY,USERINFO])

举例 :

select parse_url('http://facebook.com/path/p1.php?query=1', 'PROTOCOL') from dual;	
																---http
select parse_url('http://facebook.com/path/p1.php?query=1', 'HOST')  from dual;
																	---facebook.com
select parse_url('http://facebook.com/path/p1.php?query=1', 'REF') from dual;	
																---空
select parse_url('http://facebook.com/path/p1.php?query=1', 'PATH') from dual;	
																---/path/p1.php
select parse_url('http://facebook.com/path/p1.php?query=1', 'QUERY')from dual;	
																---空
select parse_url('http://facebook.com/path/p1.php?query=1', 'FILE') from dual;
																---/path/p1.php?query=1
select parse_url('http://facebook.com/path/p1.php?query=1', 'AUTHORITY')from dual;
																---facebook.com
select parse_url('http://facebook.com/path/p1.php?query=1', 'USERINFO')from dual;
																---空

2、字符串连接函数(需要String类型): concat和concat_ws

用法:

concat(str1,SEP,str2,SEP,str3,……)   或者  
concat_ws(SEP,str1,str2,str3, ……) (SEP为连接符)

举例:

select concat('江苏省','-','南京市','-','玄武区','-','徐庄软件园');	
---江苏省-南京市-玄武区-徐庄软件园
select concat_ws('-','江苏省','南京市','玄武区','徐庄软件园');	
---江苏省-南京市-玄武区-徐庄软件园

3、当前的系统时间:unix_timestamp() from_unixtime

用法:

unix_timestamp()  或者  
from_unixtime(unix_timestamp(),"patten"

举例:

select unix_timestamp()	
---1484532291
select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss');	
---2020-12-12 08:32:15

4、字符串替换函数(将字符串A 中的B 用 C 替换):regexp_replace

用法:

regexp_replace(string A, string B, string C) 

举例:

select regexp_replace('www.tuniu.com','tuniu','jd');	
---www.jd.com

5、重复N次字符串:repeat

用法:

 repeat(string str, int n)

举例:

select repeat('ab',3);	
---ababab

6、补齐字符串:lpad rpad

用法:

lpad(string str, int len, string pad)
或者 
rpad(string str, int len, string pad)

举例:

select lpad('ab',7,'k');		---kkkkkab
select rpad('ab',7,'k');		---abkkkkk

7、 删除字符串两边的空格(中间的会保留):trim

用法:

trim(string A), ltrim(string A) ,rtrim(string A)

举例:

select trim('   kim   bo   ')	---kim   bo
select ltrim('   kim   bo   ')	---kim   bo
select rtrim('   kim   bo   ')	---   kim   bo

请添加图片描述
请添加图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值