请注意!请注意!请注意!重要的事情说三遍,hive中的substr用法是这样子使用的:
使用语法: substr(string A, int start),substring(string A, int start) 两者用法一样,两个参数
说明:返回字符串A从start位置到结尾的字符串
举例演示:
hive> select substr('abcde',3) from test;//意为从第三个开始截取,一直到结尾。a的下标为1。
cde
hive> select substring('abcde',3) from test;
cde
hive> select substr('abcde',-1) from testl; //截取最后一位
e
使用语法: substr(string A, int start, int len),substring(string A, intstart, int len),两者用法一样,三个参数
说明:返回字符串A从start位置开始,长度为len的字符串
举例演示:
hive> select substr('abcde',3,2) from test;//从第三个起开始截取两个步长
cd
hive> select substring('abcde',3,2) from testl;
cd
hive>select substring('abcde',-2,2) from test;//截取最后两个
de
注:正数从前向后截取,负数从后向前截取。