MySQL 内置函数之字符串函数
MySQL About 825 words字符串函数
- 查看字符的
ascii码值ascii(str),str是空串时返回0
select ascii('a');
- 查看
ascii码值对应的字符char(数字)
select char(97);
- 拼接字符串
concat(str1,str2...)
select concat(12,34,'ab');
- 包含字符个数
length(str)
select length('abc');
- 截取字符串
left(str,len)返回字符串str的左端len个字符right(str,len)返回字符串str的右端len个字符substring(str,pos,len)返回字符串str的位置pos起len个字符
select substring('abc123',2,3);
- 去除空格
ltrim(str)返回删除了左空格的字符串strrtrim(str)返回删除了右空格的字符串strtrim([方向 remstr from str)返回从某侧删除remstr后的字符串str,方向词包括both、leading、trailing,表示两侧、左、右
select trim(' bar ');
select trim(leading 'x' FROM 'xxxbarxxx');
select trim(both 'x' FROM 'xxxbarxxx');
select trim(trailing 'x' FROM 'xxxbarxxx');
- 返回由
n个空格字符组成的一个字符串space(n)
select space(10);
- 替换字符串
replace(str,from_str,to_str)
select replace('abc123','123','def');
- 大小写转换,函数如下
lower(str)upper(str)
select lower('aBcD');
Views: 3,251 · Posted: 2019-04-07
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...