字串函式
1.int ascii(string str)
返回第乙個字元的ascii碼值
demo:select ascii('abcde')
result:97
string
2.base64(binary bin)
二進位制轉為base 64
3.int character_length(string str)
返回字元長度,2.2.0版本以上支援
demo:select character_length('abcde')
result:5
4.string concat_ws(string sep, array)
concat_ws(string sep, string a, string b...)
以sep為分割符,連線字串
demo:select concat_ws(',','ab','cd','ga')
result:ab,cd,ga
5.string concat(string|binary a, string|binary b...)
連線字串
demo:select concat('ad','cd')
result:adcd
6.int field(val t,val1 t,val2 t,val3 t,...)
得到fieldt的數值
demo:select field('world','say','hello','world','say')
result:3
7.int find_in_set(string str, string strlist)
返回str 在strlist第一次出現中的第幾個位置
demo:select find_in_set('def', 'abc,b,ab,c,def')
result:5
8.string get_json_object(string json_string, string path)
處理json資料格式
資料準備,]
}demo:
get_json_object(json_data,'$.va[0].age')
結果 12
get_json_object(json_data,'$.name')
world
9.int instr(string str, string substr)
返回substr出現在str中的位置
demo:select instr('abdef', 'ef')
result:4
10.int length(string a)
返回字串長度
demo:select length('adg')
result:3
11.string lower(string a) lcase(string a)
所有字元換成小寫的字元
demo:select lower('foobar')
result:foobar
demo:select lcase('foobar')
result:foobar
同理upper(string a) ucase(string a)
全部換成大寫
12.string ltrim(string a)
去掉左邊所有的空格
demo:select ltrim(' dda ')
result:dda
同理還有rtrim去掉右邊空格,trim去掉所有空格
13.string repeat(string str, int n)
對str進行重複
demo:select repeat('ad',2)
result:adad
14.string replace(string a, string old, string new)
替換字元
demo:select replace('abcd','a','f')
result:fbcd
15. string reverse(string a)
字串反轉
demo:abcd
result:dcba
16.array split(string str, string pat)
按pat進行切分
demo:select json_data,split(json_data,',')
result:返回結果是乙個陣列
va,ew,gd,ga ["va","ew","gd","ga"]
17.string substr(string|binary a, int start, int len)
substring(string|binary a, int start, int len)
擷取字串
demo:select substring('abcdde',2,4)
bcdd
雜項函式
1.int hash('ad')
返回乙個hash值
demo:select hash('ad')
result:3107
2.string current_user()
得到當前登入使用者
3.current_database()
得到當前使用資料庫
4.string md5(string/binary) 1.3.0版本支援
返回字串的md5值
5.string sha1(string/binary)
sha(string/binary)
返回安全hash演算法加密後的值
6.string version()
返回hive版本號,挺有用的,經常通過版本號來判斷是否具有新特性
udaf函式
使用者自定義聚合函式
多行輸出一行
列轉多行
select id,db_ta_name
from
dj_ods_ds.o_t_job_hive
lateral view explode(split(dependency_table,',')) te as db_ta_name
lateral view關鍵字把explode產生的多行或多列變成乙個檢視,然後再與其他的資料聚合在一起。
hive 去重 字串 hive 函式
substr string a,int start,int len substring string a,intstart,int len 用法一樣,三個引數 返回值 string 說明 返回字串a從start位置開始,長度為len的字串,下標預設為1.若沒有長度預設到結尾。round round ...
hive函式 split 字串分割函式
hive字串分割函式 split str,regex splits str around occurances that match regex time taken 0.769 seconds,fetched 1 row s 返回值為乙個陣列 a.基本用法 例1 split a,b,c,d 得到的...
hive函式 split 字串分割函式
hive字串分割函式 split str,regex splits str around occurances that match regex time taken 0.769 seconds,fetched 1 row s 返回值為乙個陣列 a.基本用法 例1 split a,b,c,d 得到的...