語法: split(string str, string pat)
返回值: array
說明: 按照pat字符串分割str,會返回分割后的字符串數組
舉例:
1.基本用法
hive> select split('abcdef', 'c') from test;
["ab", "def"]
2.截取字符串中的某個值
hive> select split('abcdef', 'c')[0] from test;
ab
3.特殊字符
如正則表達式中的特殊符號作為分隔符時,需做轉義 (前綴加上\)
hive> select split('ab_cd_ef', '\_')[0] from test;
ab
hive> select split('ab?cd_ef', '\\?')[0] from test;
ab
如果是在shell中運行,則(前綴加上\\)
hive -e "select split('ab?cd_ef', '\\\\?')[0] from test"