2.7 TRIM(str):返回字符串str,所有前缀或后缀被删除了。
1. LTRIM(str):返回删除了其前置空格字符的字符串str。
2. RTRIM(str):返回删除了其拖后空格字符的字符串str。
实例
MariaDB [study_db]> SELECT TRIM(' HUAGN ');
+---------------------+
| TRIM(' HUAGN ') |
+---------------------+
| HUAGN |
+---------------------+
1 row in set (0.00 sec)
2.8 替换REPLACE(str, from_str, to_str):返回字符串str,其字符串from_str的所有出现由字符串to_str代替。
MariaDB [study_db]> SELECT REPLACE('NODEJS', 'JS', 'study');
+----------------------------------+
| REPLACE('NODEJS', 'JS', 'study') |
+----------------------------------+
| NODEstudy |
+----------------------------------+
1 row in set (0.00 sec)
2.9 REPEAT(str,count):返回由重复countTimes次的字符串str组成的一个字符串。如果count <= 0,返回一个空字符串。如果str或count是NULL,返回NULL。
MariaDB [study_db]> SELECT REPEAT('HHW', 24);
+--------------------------------------------------------------------------+
| REPEAT('HHW', 24) |
+--------------------------------------------------------------------------+
| HHWHHWHHWHHWHHWHHWHHWHHWHHWHHWHHWHHWHHWHHWHHWHHWHHWHHWHHWHHWHHWHHWHHWHHW |
+--------------------------------------------------------------------------+
1 row in set (0.00 sec)
2.10.1 REVERSE(str):返回颠倒字符顺序的字符串str。
MariaDB [study_db]> SELECT REVERSE('123456');
+-------------------+
| REVERSE('123456') |
+-------------------+
| 654321 |
+-------------------+
1 row in set (0.00 sec)
2.10.2 SUBSTRING(str, pos):取出str前pos个字符, 返回剩余的字符;
MariaDB [study_db]> SELECT SUBSTRING('ABCDEFGHIJKLMN', 4);
+--------------------------------+
| SUBSTRING('ABCDEFGHIJKLMN', 4) |
+--------------------------------+
| DEFGHIJKLMN |
+--------------------------------+
1 row in set (0.00 sec)
2.10.3 INSERT(str,pos,len,newstr):返回字符串str,在位置pos起始的子串且len个字符长的子串由字符串newstr代替。
MariaDB [study_db]> SELECT INSERT('1234567890', 4, 2, 'mariadb');
+---------------------------------------+
| INSERT('1234567890', 4, 2, 'mariadb') |
+---------------------------------------+
| 123mariadb67890 |
+---------------------------------------+
1 row in set (0.00 sec)