1、字符串函数
- concat(s1,s2,…sn)
将传入的参数连成字符串,如果与null相连,则值也为null
mysql> select concat('aaa','bbb','ccc'),concat('aaa',null);
+---------------------------+--------------------+
| concat('aaa','bbb','ccc') | concat('aaa',null) |
+---------------------------+--------------------+
| aaabbbccc | NULL |
+---------------------------+--------------------+
1 row in set (0.00 sec)
- insert(str,x,y,instr)
将字符串str从第x位开始,y个字符长的子串替换为instr
mysql> select insert('hello world',2,4,'ll');
+--------------------------------+
| insert('hello world',2,4,'ll') |
+--------------------------------+
| hll world |
+--------------------------------+
1 row in set (0.00 sec)
- lower(str),upper(str)
将字符串str转为小写、大写
mysql> select lower('HELLO'),upper('hello');
+----------------+----------------+
| lower('HELLO') | upper('hello') |
+----------------+----------------+
| hello | HELLO |
+----------------+----------------+
1 row in set (0.00 sec)
- left(str,x),right(str,x)
返回字符串str最左边、最右边x个字符
mysql> select left('hello',2),right('hello',2);
+-----------------+------------------+
| left('hello',2) | right('hello',2) |
+-----------------+------------------+
| he | lo |
+-----------------+------------------+
1 row in set (0.00 sec)
- substring(str,x,y)
返回从字符串str中的第x位开始,y字符长度的子串
mysql> select substring('hello world',5,3);
+------------------------------+
| substring('hello world',5,3) |
+------------------------------+
| o w |
+------------------------------+
1 row in set (0.00 sec)
- lpad(str,n,pad),rpad(str,n,pad)
用字符串pad对str最左边、最右边进行填充,直到长度达到n位为止
mysql> select lpad('hello',18,'world'),rpad('hello',18,'world');
+--------------------------+--------------------------+
| lpad('hello',18,'world') | rpad('hello',1