replace(str,from_str,to_str) 是 MySQL 的一个 字符串函数。此方法用于字符串的替换,它区分大小写。
语法
select replace(str, from_str, to_str);
参数
str: 原字符串
from_str: 要替换的字符串
to_str: 替换的字符串
示例 1
select replace('baidu', 'bai', 'yi');
输出:
mysql> select replace('baidu', 'bai', 'yi');
+-------------------------------+
| replace('baidu', 'bai', 'yi') |
+-------------------------------+
| yidu |
+-------------------------------+
1 row in set (0.00 sec)
示例 2
select replace('MYSQL', 'sql', 'mysql');
输出:
mysql> select replace('MYSQL', 'sql', 'mysql');
+----------------------------------+
| replace('MYSQL', 'sql', 'mysql') |
+----------------------------------+
| MYSQL |
+----------------------------------+
1 row in set (0.00 sec)