MySQL String Functions and Operators(字符串处理)

NameDescription例子
ASCII(str)返回字符ascii码SELECT ASCII('2'); # -> 50
BIN(N)返回字符的二进制值SELECT BIN(12); # -> '1100'
BIT_LENGTH()Return length of argument in bits
CHAR(N,... [USING charset_name])将整型转换为字符SELECT CHAR(77,121,83,81,'76'); # -> 'MySQL'
CHAR_LENGTH()Return number of characters in argument
CHARACTER_LENGTH()Synonym for CHAR_LENGTH()
CONCAT(str1,str2,...)拼贴字符串SELECT CONCAT('My', 'S', 'QL'); # -> 'MySQL'
CONCAT_WS()Return concatenate with separator
ELT()Return string at index number
EXPORT_SET()Return a string such that for every bit set in the value bits, you get an on string and for every unset bit, you get an off string
FIELD(str,str1,str2,str3,...)Returns the index (position) of str in the str1, str2, str3, … list.SELECT FIELD('Bb', 'Aa', 'Bb', 'Cc', 'Dd', 'Ff'); # -> 2
FIND_IN_SET()Index (position) of first argument within second argument
FORMAT(X,D[,locale])格式化字符串,D是小数点保留位SELECT FORMAT(12332.123456, 4); # -> '12,332.1235'
FROM_BASE64()Decode base64 encoded string and return result
HEX()Hexadecimal representation of decimal or string value
INSERT(str,pos,len,newstr)插入字符SELECT INSERT('Quadratic', 3, 4, 'What'); # -> 'QuWhattic'
INSTR(str,substr)索引子字符串SELECT INSTR('foobarbar', 'bar'); # -> 4
LCASE()Synonym for LOWER()
LEFT(str,len)从左边截取字符串SELECT LEFT('foobarbar', 5); # -> 'fooba'
LENGTH(str)返回字符串长度
LIKESimple pattern matching
LOAD_FILE()Load the named file
LOCATE(substr,str), LOCATE(substr,str,pos)索引字符串SELECT LOCATE('bar', 'foobarbar'); # -> 4
LOWER(str)小写SELECT LOWER('QUADRATICALLY'); -> 'quadratically'
LPAD(str,len,padstr)左边填充字符串,len是填充后的长度SELECT LPAD('hi',4,'??'); # -> '??hi'
LTRIM(str)删除左边的空白SELECT LTRIM(' barbar'); # -> 'barbar'
MAKE_SET()Return a set of comma-separated strings that have the corresponding bit in bits set
MATCHPerform full-text search
MID(str,pos,len)SUBSTRING(str,pos,len)
NOT LIKENegation of simple pattern matching
NOT REGEXPNegation of REGEXP
OCT()Return a string containing octal representation of a number
OCTET_LENGTH()Synonym for LENGTH()
ORD()Return character code for leftmost character of the argument
POSITION()Synonym for LOCATE()
QUOTE()Escape the argument for use in an SQL statement
REGEXPWhether string matches regular expression
REGEXP_INSTR()Starting index of substring matching regular expression
REGEXP_LIKE()Whether string matches regular expression
REGEXP_REPLACE()Replace substrings matching regular expression
REGEXP_SUBSTR()Return substring matching regular expression
REPEAT(str,count)重复字符串SELECT REPEAT('MySQL', 3); # -> 'MySQLMySQLMySQL'
REPLACE(str,from_str,to_str)替换字符串SELECT REPLACE('www.mysql.com', 'w', 'Ww'); # -> 'WwWwWw.mysql.com'
REVERSE(str)反转字符串SELECT REVERSE('abc'); # -> 'cba'
RIGHT(str,len)从右边截取字符串SELECT RIGHT('foobarbar', 4); # -> 'rbar'
RLIKEWhether string matches regular expression
RPAD(str,len,padstr)右边填充空白SELECT RPAD('hi',5,'?'); # -> 'hi???'
RTRIM(str)右边删除空白SELECT RTRIM('barbar '); # -> 'barbar'
SOUNDEX()Return a soundex string
SOUNDS LIKECompare sounds
SPACE(N)生成空白字符SELECT SPACE(6); # ->-> ' '
STRCMP()Compare two strings
SUBSTR()Return the substring as specified
SUBSTRING(str,pos,len)截取字符串SELECT SUBSTRING('Quadratically',5,6); # -> 'ratica'
SUBSTRING_INDEX()Return a substring from a string before the specified number of occurrences of the delimiter
TO_BASE64()Return the argument converted to a base-64 string
TRIM([{BOTH ....删除空白SELECT TRIM(' bar '); # -> 'bar'
UCASE()UPPER()
UNHEX()Return a string containing hex representation of a number
UPPER(str)大写SELECT UPPER('Hej'); # -> 'HEJ'
WEIGHT_STRING()Return the weight string for a string

参考:
https://dev.mysql.com/doc/refman/8.0/en/string-functions.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值