MySQL字符串函数是用于处理和操作字符串数据的一系列内置函数,这些函数可以帮助我们轻松地完成各种字符串操作,如截取、替换、拼接等,本文将对MySQL中的常用字符串函数进行详细的汇总介绍。
字符串长度函数
1、CHAR_LENGTH():返回字符串的字符数。
语法:CHAR_LENGTH(str)
2、CHARACTER_LENGTH():返回字符串的字符数。
语法:CHARACTER_LENGTH(str)
3、LENGTH():返回字符串的字节数。
语法:LENGTH(str)
4、LENGTHB():返回字符串的字节数。
语法:LENGTHB(str)
字符串截取函数
1、SUBSTRING():从字符串中截取子串。
语法:SUBSTRING(str, pos, len)
2、MID():从字符串中截取子串。
语法:MID(str, pos, len)
3、LEFT():从字符串左侧截取指定长度的子串。
语法:LEFT(str, len)
4、RIGHT():从字符串右侧截取指定长度的子串。
语法:RIGHT(str, len)
5、SUBSTR():从字符串中截取子串。
语法:SUBSTR(str, pos, len)
字符串替换函数
1、REPLACE():替换字符串中的子串。
语法:REPLACE(str, from_str, to_str)
2、REPLACE():替换字符串中的子串。
语法:REPLACE(str, from_str, to_str)
字符串拼接函数
1、CONCAT():连接两个或多个字符串。
语法:CONCAT(str1, str2, ..., strN)
2、CONCAT_WS():连接两个或多个字符串,可以指定分隔符。
语法:CONCAT_WS(separator, str1, str2, ..., strN)
字符串查找函数
1、LOCATE():查找子串在字符串中的位置。
语法:LOCATE(substr, str, [start])
2、INSTR():查找子串在字符串中的位置。
语法:INSTR(str, substr)
3、POSITION():查找子串在字符串中的位置。
语法:POSITION(substr IN str)
字符串匹配函数
1、LIKE():判断一个字符串是否匹配给定的模式。
语法:LIKE pattern ESCAPE 'escape_char'
2、REGEXP():使用正则表达式匹配字符串。
语法:REGEXP pattern MODE modifiers 'i' 'c' 'n' 'm' 'x' 'o' 'u' 's' 'e' 'g' 'p' 'w' '+' '*' '?' '(' ')' '[' ']' '{' '}' '|' '\' '\'' '\'' '\'' ''' '\'' '\'' '\'' ''' '\'' '\'' '\'' ''' '\'' '\'' '\'' ''' '\'' '\'' '\'' ''' '\'' '\'' '\'' ''' '\'' '\'' '\'' ''' '\'' '\'' '\'' ''' '\'' '\'' '\'' ''' '\'' '\'' '\'' ''' '\'' '\'' '\'' ''' '\'' '\'' '\'' ''' '\'' '\'' '\--' '+' '*' '?' '(' ')' '[' ']' '{' '}' '|' '\\' '\--' '+' '*' '?' '(' ')' '[' ']' '{' '}' '|' '\\' '--' '+' '*' '?' '(' ')' '[' ']' '{' '}' '|' '\\' '\--' '+' '*' '?' '(' ')' '[' ']' '{' '}' '|' '\' '\--' '+' '*' '?' '(' ')' '[' ']' '{' '}' '|' '\\' '\--' '+' '*' '?' '(' ')' '[' ']' '{' '}' '|' '\\' '\--' '+' '*' '?' '(' ')' '[' ']' '{' '}' '|' '\\-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->1. INSTR()函数和LOCATE()函数有什么区别?
原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/367498.html