You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hive>select reverse(abcedfg’) from table_name;
gfdecba
3. 字符串连接函数:concat
语法: concat(string A, string B…)
返回值: string
说明:返回输入字符串连接后的结果,支持任意个输入字符串
举例:
hive>select concat(‘abc’,'def’,'gh’) from table_name;
abcdefgh
4. 带分隔符字符串连接函数:concat_ws
语法: concat_ws(string SEP, string A, string B…)
返回值: string
说明:返回输入字符串连接后的结果,SEP表示各个字符串间的分隔符
举例:
hive>select concat_ws(',','abc','def','gh') from table_name;
abc,def,gh
5. 字符串截取函数:substr,substring
语法: substr(string A, int start),substring(string A, int start)
返回值: string
说明:返回字符串A从start位置到结尾的字符串
举例:
hive>select substr('abcde',3) from table_name;
cde
hive>selectsubstring('abcde',3) from table_name;
cde
hive> selectsubstr('abcde',-1) from table_name; (和ORACLE相同)
e
6. 字符串截取函数:substr,substring
语法: substr(string A, int start, int len),substring(string A, intstart, int len)
返回值: string
说明:返回字符串A从start位置开始,长度为len的字符串
举例:
hive>select substr('abcde',3,2) from table_name;
cd
hive>selectsubstring('abcde',3,2) from table_name;
cd
hive>selectsubstring('abcde',-2,2) from table_name;
de
7. 字符串转大写函数:upper,ucase
语法: upper(string A) ucase(string A)
返回值: string
说明:返回字符串A的大写格式
举例:
hive>selectupper('abSEd') from table_name;
hive>select ucase('abSEd') from table_name;
8. 字符串转小写函数:lower,lcase
语法: lower(string A) lcase(string A)
返回值: string
说明:返回字符串A的小写格式
举例:
hive>selectlower('abSEd') from table_name;
absed
hive>select lcase('abSEd') from table_name;
absed
9. 去空格函数:trim
语法: trim(string A)
返回值: string
说明:去除字符串两边的空格
举例:
hive>selecttrim(' abc ') from table_name;
abc
10. 左边去空格函数:ltrim
语法: ltrim(string A)
返回值: string
说明:去除字符串左边的空格
举例:
hive>select ltrim(' abc ') from table_name;
abc
11. 右边去空格函数:rtrim
语法: rtrim(string A)
返回值: string
说明:去除字符串右边的空格
举例:
hive>select rtrim(' abc ') from table_name;
abc
12. 正则表达式替换函数:regexp_replace
语法: regexp_replace(string A, string B, string C)
返回值: string
说明:将字符串A中的符合java正则表达式B的部分替换为C。注意,在有些情况下要使用转义字符,类似oracle中的regexp_replace函数。
举例:
hive>select regexp_replace('foobar', 'oo|ar', '') from table_name;
fb
13. 正则表达式解析函数:regexp_extract
语法: regexp_extract(string subject, string pattern, int index)
返回值: string
说明:将字符串subject按照pattern正则表达式的规则拆分,返回index指定的字符。
举例:
hive>select regexp_extract('foothebar', 'foo(.*?)(bar)', 1) fromtable_name;
the
hive>select regexp_extract('foothebar', 'foo(.*?)(bar)', 2) fromtable_name;
bar
hive>select regexp_extract('foothebar', 'foo(.*?)(bar)', 0) fromtable_name;
foothebar
注意,在有些情况下要使用转义字符,下面的等号要用双竖线转义,这是java正则表达式的规则。
select data_field,
regexp_extract(data_field,'.*?bgStart\\=([^&]+)',1) as aaa,
regexp_extract(data_field,'.*?contentLoaded_headStart\\=([^&]+)',1) as bbb,
regexp_extract(data_field,'.*?AppLoad2Req\\=([^&]+)',1) as ccc
from pt_nginx_loginlog_st
where pt ='2012-03-26'limit2;