MySQL 你没见过的字符串函数

avatar
作者
筋斗云
阅读量:24

concat mysql_concat mysql_concat mysql

架构师大咖

架构师大咖,打造有价值的架构师交流平台。分享架构师干货、教程、课程、资讯。架构师大咖,每日推送。

公众号

该公众号已被封禁

抓紧get新技能吧~

MySQL常用字符串函数

大写转小写 lower()

mysql>selectlower("KFDSKGS");

+------------------+

|lower("KFDSKGS")|

+------------------+

|kfdskgs|

+------------------+

小写转大写 upper()

mysql>selectupper("fdssssssss");

+-------------------+

|upper("fdssssssss")|

+-------------------+

|FDSSSSSSSS|

+-------------------+

字符串的连接 concat()

mysql>selectconcat("My","S","QL");

+--------------------+

|concat("My","S","QL")|

+--------------------+

|MySQL|

+--------------------+

截取字符串 substr() / substring()

mysql>selectsubstring("Helloworld",5);

+-----------------------+

|substring("Helloworld",5)|

+-----------------------+

|oworld|

+-----------------------+

1rowinset(0.07sec)

mysql>selectsubstring("Hhlloworld",5,3);

+-------------------------+

|substring("Hhlloworld",5,3)|

+-------------------------+

|ow|

+-------------------------+

1rowinset(0.07sec)

mysql>selectsubstring("Hhlloworld",-5);

+------------------------+

|substring("Hhlloworld",-5)|

+------------------------+

|world|

+------------------------+

1rowinset(0.08sec)

查看字符串的长度 length() 这里的UTF8 中文是占用两个字节

mysql>selectlength("text");

+-------------+

|length("text")|

+-------------+

|4|

+-------------+

mysql>selectlength("你好");

+--------------+

|length("你好")|

+--------------+

|6|

+--------------+

返回一共有多少个字 char_length() 几个字母就是返回多少

mysql>selectchar_length("text");

+------------------+

|char_length("text")|

+------------------+

|4|

+------------------+

1rowinset(0.07sec)

返回字串第一次出现的位置 instr()

mysql>selectinstr("footer","ter");

+-----------------+

|instr("footer","ter")|

+-----------------+

|4|

+-----------------+

如果不够指定的位数则做什么操作 lpad()

mysql>selectlpad("hello",10,"0");

+-----------------+

|lpad("hello",10,"0")|

+-----------------+

|00000hello|

+-----------------+

1rowinset(0.13sec)

位数不够右边补0 rpad()

mysql>selectrpad("hello",10,"0");

+------------------+

|rpad("hello",10,"0")|

+------------------+

|hello00000|

+------------------+

1rowinset(0.13sec)

去除两边的空格 trim()

mysql>selecttrim('bar');

+-------------+

|trim('bar')|

+-------------+

|bar|

+-------------+

1rowinset(0.13sec)

指定字符串截取 左边截取字符串 trim()

mysql>selecttrim(leading'X'from'XXXXXtrimleadingXXXX');

+---------------------------------------+

|trim(leading'X'from'XXXXXtrimleadingXXXX')|

+---------------------------------------+

|trimleadingXXXX|

+---------------------------------------+

1rowinset(0.13sec)

指定去除字符串右边的xyz,左边截取字符串 trim()

mysql>selecttrim(trailing'zyz'from'barxxyz');

+----------------------------+

|trim(trailing'zyz'from'barxxyz')|

+----------------------------+

|barxxyz|

+----------------------------+

1rowinset(0.12sec)

指定去除字符串两边的X trim()

mysql>trim(both'X'from'XXXXXXXtrimbothXXXXXXX')

+----------------------------------------+

|trim(both'X'from'XXXXXXXtrimbothXXXXXXX')|

+----------------------------------------+

|trimboth|

+----------------------------------------+

1rowinset(0.13sec)

替换字符串 replace()

mysql>selectreplace('www.mysql.com','w','W');

+------------------------------+

|replace('www.mysql.com','w','W')|

+------------------------------+

||

+------------------------------+

repeat(str,count) 将字符串str重复count次后返回

mysql>selectrepeat('MySQL',3);

+--------------------+

|repeat('MySQL',3)|

+--------------------+

|MySQLMySQLMySQL|

+--------------------+

1rowinset(0.07sec)

reverse() 将字符串反转后返回

mysql>selectreverse("abcdef");

+-----------------+

|reverse("abcdef")|

+-----------------+

|fedcba|

+-----------------+

1rowinset(0.06sec)

fromat() 科学技术方式

mysql>selectformat(129021,4);

+----------------+

|format(129021,4)|

+----------------+

|129,021.0000|

+----------------+

完结~

concat mysql_concat mysql_concat mysql

Python入门到精通

Python入门到精通:人生苦短,我用Python!Python每日推送、Python教程、Python资料、Python视频、Python项目、Python学习等。

公众号

该公众号已被封禁

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!