大数据入门到精通14--hive 对 字符串的操作
一、基本操作
concat(string,string,string)
concat_ws(string,string,string)
select customer_id,concat_ws(" ",first_name,last_name),email,address_id from customer;
lower(string)
initcap(string)
if 表达式
select customer_id,if (length(first_name)>6 , substring(first_name,0,5),first_name),email,address_id from customer limit 10;
upper(string)
select if (length("abcdefghijk")>6, "a","b");
ltrim(string)
rtrim(string)
trim(string)
length(string)
reverse(string)
split(string,"\\|")
不能直接使用split里面的| 因为那样会把字符串里面的每一个字符都分开,有特定的含义。
select split("abc,def,aaa| bbb",",");
二。高级字符串处理
rpad(string,20," ")
lpad(string,20," ")
regexp_replace(string,"original","dest")
instr(str1,str2),返回字符串中的第几个字符开始
hive> select instr("abcdefadef","def");
OK
4
instr用在where字句中,等同于 like字句。
select film_id,rpad(title,25," "),description from film where lower(description) like "%ancient%";