标准函数
字符函数
| 返回值 | 函数 | 描述 | 举例 | 结果 |
|---|---|---|---|---|
| string | concat | 字符串拼接 | select concat(‘abc’,‘cd’,‘e’) | abccde |
| string | instr(string str, string substr) | 查找字符串str中子字符串substr出现的位置 | select instr(‘abcdabcd’,‘cd’) | 3 |
| string | length | 返回字符串的长度 | select length(‘abcdef’) | 6 |
| string | locate(string substr, string str[, int pos]) | 查找字符串str中的pos位置后字符串substr第一次出现的位置 | select locate(‘cd’,‘abcdabcd’,4) | 7 |
| string | upper(string A) | 将字符串A中的字母都变为大写 | select upper(‘abcdef’) | ABCDEF |
| string | lower(string A) | 将字符串A中的字母都变为小写 | select lower(‘ASASre’) | asasre |
| string | regexp_replace | 按正则表达式将字符串中符合条件的部分替换成指定的字符串 | select regexp_replace(‘1999/5-5 13:24:12.234’,’\.[0-9]+’,’’) | abccde |
| string | split | 通过正则表达式分割 | select split(‘1999/5-5 13:24:12.234’,’\.’)[0] | 1999/5-5 13:24:12 |
| string | substring | 从指定位置开始截取指定长度的字符串 | select substring(‘1999/5-5 13:24:12.234’,1,8) | 1999/5-5 |
| string | trim | 去掉两端的空格 | select trim(" 1999/5-5 13:24:12.234 ") | 1999/5-5 13:24:12.234 |
| string | str_to_map | 将字符串按照指定分隔符转换成Map | select str_to_map(‘1999/5-5 13:24:12.234’,’ ') | {“13”:“24:12.234”,“1999/5-5”:null} |
| string | encode | 用指定字符集将字符串编码成二进制值 | select encode(‘你好’,‘utf-8’) | 你好 |
| string | reverse | 反转 | select reverse(‘abcd’) | dcba |
| string | concat_ |

这篇博客详细介绍了Hive的内置函数,包括字符函数、类型转换、数学运算、日期处理、集合操作和条件函数。重点讨论了聚合函数的使用,如在遇到null值时如何处理,以及它们在GROUP BY语句中的应用。同时提到了表生成函数,这类函数的输出可以直接作为新的表格使用。
最低0.47元/天 解锁文章
2610

被折叠的 条评论
为什么被折叠?



