返回类型 | 函数名 | 描述 |
int | length(string A) | 返回字符串A的长度; select length(xxxxxx) select length(某字段)from 某表 此函数在实际工作,可以用于校验手机号,身份证号等信息的合法性 |
string | reverse(string A) | 返回字符串A的反转结果 select reverse(‘abcd’); select reverse(某字段)from 某表 |
string | concat(string A, string B…) | 字符串连接函数 select concat ('a','b'); select concat(id,name) from stu; select concat(id,',',name) from stu; |
string | concat_ws(string SEP, string A, string B…) | 带分隔符字符串连接函数:concat_wsselect concat_ws('.','www','baidu','com'); //www.baidu.com |
string | substr | substr,substringselect substr('abcde',2);从第二个截,截到结尾select substr('abcde',1,3);从第一个截,截三个长度select substr('wfeww',-2);从尾部截,截两个长度 可以用于比如截取身份证后几位操作 |
string | upper(string a)ucase(string a) | 转大写 |
string | lower(string a)lcase(string a) | 转小写 |
string | trim(string a) | 去空格 select trim (‘ aa ’); |
string | ltrim | 左边去空格 |
string | rtrim(string a) | 右边去空格 |
string | regexp_replace(string A, string B, string C) | 将字符串A中的符合java正则表达式B的部分替换为C。注意,在有些情况下要使用转义字符,对需要转义的字符,用[],比如[*],类似oracle中的regexp_replace函数。 select regexp_replace('foobar', 'oo|ar', ''); |
string | regexp_extract(string subject, string pattern, int index) | 将字符串subject按照pattern正则表达式的规则拆分,返回index指定的字符select regexp_extract('foothebar', 'foo(.*)(bar)', 1); //the select regexp_extract('foothebar', 'foo(.*)(bar)', 2);//barselect regexp_extract('foothebar', 'foo(.*)(bar)', 0);//全取 foothebar |
string | repeat(string str, int n) | 返回重复n次后的str字符串select repeat('abc',5) |
array | split(string str, string pat) | 分割字符串函数: split按照pat字符串分割str,会返回分割后的字符串数组select split('abtcdtef','t');["ab","cd","ef"] |