1 1、字符串长度函数:length(X)(返回字符串X的长度) 2 select length('qwerty') from table --6 3 4 2、字符串反转函数:reverse(X)(返回字符串X反转的结果) 5 select reverse('qwerty') from table --ytrewq 6 7 3、字符串连接函数:concat(X,Y,...)(返回输入字符串连接后的结果,支持任意个输入字符串连接) 8 select concat('abc','qwe','rty') from table --abcqwerty 9 10 4、带分隔符字符串连接函数:concat_ws(X,y,Z)(返回输入字符串连接后的结果,X表示各个字符串间的分隔符) 11 select concat_ws('/','abc','qwe','rty') from table --abc/qwe/rty 12 13 5、字符串截取函数:substr(X,Y,Z)/substring(X,Y,Z)(返回字符串X从Y位置开始,截取长度为Z的字符串) 14 select substr('qwerty',1,3) from table --qwe 15 16 6、字符串转大写函数:upper(X)/ucase(X)(返回字符串X的大写格式) 17 select upper('qwERt') from table --QWERT 18 select ucase('qwERt') from table --QWERT 19 20 7、字符串转小写函数:lower(X)/lcase(X)(返回字符串X的小写格式) 21 select lower('qwERt') from table --qwert 22 select lcase('qwERt') from table --qwert 23 24 8、去空格函数:trim(X)(去除X字符串两边的空格) 25 select trim(' qwe rty uiop ') from table --'qwe rty uiop' 26 左边去空格函数:ltrim(X)(去除X字符串左边的空格) 27 select ltrim(' qwe rty uiop ') from table --'qwe rty uiop ' 28 右边去空格函数:rtrim(X)(去除X字符串右边的空格) 29 select rtrim(' qwe rty uiop ') from table --' qwe rty uiop' 30 31 9、正则表达式替换函数:regexp_replace(X,Y,Z)(将字符串X中的符合java正则表达式Y的部分替换为Z:将X中与Y相同的字符串用Z替换) 32 select regexp_replace('foobar', 'o|ar', '234') from table --f234234b234 33 34 10、正则表达式解析函数:regexp_extract(X,Y,Z)(将字符串X按照Y正则表达式的规则拆分,返回Z指定的字符) 35 select regexp_extract('foothebar', 'foo(.*?)bar', 0) from table --foothebar 36 select regexp_extract('foothebar', 'foo(.*?)bar', 1) from table --the 37 select regexp_extract('foothebar', 'foo(.*?)bar', 2) from table --bar 38 39 11、URL解析函数:parse_url(X,Y,Z)(返回URL中指定的部分。X的有效值为:HOST, PATH, QUERY, REF, PROTOCOL, AUTHORITY, FILE, and USERINFO) 40 select parse_url('https://www.iteblog.com/path1/p.php?k1=v1&k2=v2#Ref1', 'HOST') from table --www.iteblog.com 41 select parse_url('https://www.iteblog.com/path1/p.php?k1=v1&k2=v2#Ref1', 'QUERY','k1') from table --v1 42 43 12、json解析函数:get_json_object(X,Y)(解析json的字符串X,返回Y指定的内容) 44 例:X='[{"height":540,"size":79466,"width":960,"card_info":{"title":"超火热门小说","mp_tag_type":0,"head_desc_type":2,"pure_color_rgb":"#643C15","font_color":"#FFFFFF"}}]' 45 select get_json_object(substr(X,2,length(crt_info)-2), '$.card_info.pure_color_rgb') as color_rgb from table --#643C15 46 select get_json_object(substr(X,2,length(crt_info)-2), '$.size') as size_ from table --79466 47 48 13、空格字符串函数:space([int] X)(返回长度为X的字符串) 49 select space(10) from table --空 50 select length(space(10)) from table --10 51 52 14、重复字符串函数:repeat(X,Y)(返回重复Y次后的X字符串) 53 select repeat('abc',3) from table --abcabcabc 54 55 15、首字符ascii函数:ascii(X)(返回字符串X首字符的ascii码) 56 select ascii('abcde') from table --97 57 58 16、左补足函数:lpad(X,Y,Z)(将字符串X左补足到Y位:将字符串Z填充在字符串X的左边,直至字符串长度为Y) 59 备注:左补足时,补足的字符串Z要倒序补足 60 select lpad('abc',6,'wq') from table --wqwabc 61 右补足函数:rpad(X,Y,Z)(将字符串X右补足到Y位:将字符串Z填充在字符串X的右边,直至字符串长度为Y) 62 select rpad('abc',6,'wq') from table --abcwqw 63 64 17、分割字符串函数: split(X,Y)(将字符串X按照Y字符串进行分割,返回分割后的字符串数组) 65 select split('abcabcabc','b') from table --["a","ca","ca","c"] 66 67 18、集合查找函数: find_in_set(X,Y)(返回X在Y第一次出现的位置,Y是用逗号分割的字符串。如果没有找该X字符,则返回0) 68 select find_in_set('as','ad,af,as,ag') from table --3 69 select find_in_set('ak','ad,af,as,ag') from table --0