Hive常用字符串操作函数

返回类型函数名描述
intlength(string A)

返回字符串A的长度;

select length(xxxxxx)

select length(某字段)from 某表

此函数在实际工作,可以用于校验手机号,身份证号等信息的合法性

stringreverse(string A)

返回字符串A的反转结果

select reverse(‘abcd’);

select reverse(某字段)from 某表

stringconcat(string A, string B…)字符串连接函数
select concat ('a','b');
select concat(id,name) from stu;
select concat(id,',',name) from stu;
stringconcat_ws(string SEP, string A, string B…)带分隔符字符串连接函数:concat_wsselect concat_ws('.','www','baidu','com');  //www.baidu.com
stringsubstrsubstr,substringselect substr('abcde',2);从第二个截,截到结尾select substr('abcde',1,3);从第一个截,截三个长度select substr('wfeww',-2);从尾部截,截两个长度
可以用于比如截取身份证后几位操作
stringupper(string a)ucase(string a)转大写
stringlower(string a)lcase(string a)转小写
stringtrim(string a)去空格 select trim (‘ aa ’);
stringltrim左边去空格
stringrtrim(string a)右边去空格
stringregexp_replace(string A, string B, string C)将字符串A中的符合java正则表达式B的部分替换为C。注意,在有些情况下要使用转义字符,对需要转义的字符,用[],比如[*],类似oracle中的regexp_replace函数。
select regexp_replace('foobar', 'oo|ar', '');
string regexp_extract(string subject, string pattern, int index)将字符串subject按照pattern正则表达式的规则拆分,返回index指定的字符select regexp_extract('foothebar', 'foo(.*)(bar)', 1); //the select regexp_extract('foothebar', 'foo(.*)(bar)', 2);//barselect regexp_extract('foothebar', 'foo(.*)(bar)', 0);//全取 foothebar
stringrepeat(string str, int n)返回重复n次后的str字符串select repeat('abc',5)
arraysplit(string str, string pat)分割字符串函数: split按照pat字符串分割str,会返回分割后的字符串数组select split('abtcdtef','t');["ab","cd","ef"]

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值