concat
拼接多个字符串。
MariaDB [test]> select concat('a', '-', 'b', '-', 'c');
+---------------------------------+
| concat('a', '-', 'b', '-', 'c') |
+---------------------------------+
| a-b-c |
+---------------------------------+
concat_ws
使用指定的分隔符,拼接多个字符串。
CONCAT_WS() 代表 CONCAT With Separator ,是CONCAT()的特殊形式。 第一个参数是其它参数的分隔符。分隔符的位置放在要连接的两个字符串之间。分隔符可以是一个字符串,也可以是其它参数。如果分隔符为 NULL,则结果为 NULL。函数会忽略任何分隔符参数后的 NULL 值。
mysql> SELECT CONCAT_WS(',','First name','Second name','Last Name');
+-------------------------------------------------------+
| CONCAT_WS(',','First name','Second name','Last Name') |
+-------------------------------------------------------+
| First name,Second name,Last Name |
+-------------------------------------------------------+
mysql> SELECT CONCAT_WS(',','First name',NULL,'Last Name');
+----------------------------------------------+
| CONCAT_WS(',','First name',NULL,'Last Name') |
+----------------------------------------------+
| First name,Last Name |
+----------------------------------------------+
lcase
将字符串中的所有字母转换为小写字母。
MariaDB [test]> select lcase('aBcD');
+---------------+
| lcase('aBcD') |
+---------------+
| abcd |
+---------------+
ucase
将字符串中的所有字母转换为大写字母。
length
返回字符串的长度(统计的是字节数)。
MariaDB [test]> select length('abc');
+---------------+
| length('abc') |
+---------------+
| 3 |
+---------------+
trim
删除字符串两端的空格。
MariaDB [test]> select trim(' abc ');
+---------------+
| trim(' abc ') |
+---------------+
| abc |
+---------------+
ltrim
删除字符串左侧的空格。
rtrim
删除字符串右侧的空格。
repeat
将字符串重复指定的次数。
MariaDB [test]> select repeat('abc', 3);
+------------------+
| repeat('abc', 3) |
+------------------+
| abcabcabc |
+------------------+
replace
将字符串中的某个子字符串替换为指定的字符串。
MariaDB [test]> select replace('abccc', 'c', 'dd');
+-----------------------------+
| replace('abccc', 'c', 'dd') |
+-----------------------------+
| abdddddd |
+-----------------------------+
substring
截取子字符串。
MariaDB [test]> select substring('abcdef', 1, 3);
+---------------------------+
| substring('abcdef', 1, 3) |
+---------------------------+
| abc |
+---------------------------+
space
将空格重复多次。
MariaDB [test]> select concat('a', space(1), 'b', space(3), 'c');
+-------------------------------------------+
| concat('a', space(1), 'b', space(3), 'c') |
+-------------------------------------------+
| a b c |
+-------------------------------------------+
md5
对字符串进行md5加密。
MariaDB [test]> select md5('123456');
+----------------------------------+
| md5('123456') |
+----------------------------------+
| e10adc3949ba59abbe56e057f20f883e |
+----------------------------------+