首页  >  文章  >  数据库  >  MySQL中如何使用REPLACE()函数

MySQL中如何使用REPLACE()函数

WBOY
WBOY转载
2023-06-02 23:25:012678浏览

REPLACE()

REPLACE(str,from_str,to_str)函数用于将字符串 str 中所有的 from_str 替换为 to_str,返回替换后的字符串。例如:

SELECT REPLACE('MySQL字符串函数', '字符串', '日期') AS str1,
       REPLACE('MySQL字符串函数', '字符串', '') AS str2;
str1        |str2     |
------------+---------+
MySQL日期函数|MySQL函数|

另外,INSERT(str,pos,len,newstr)函数用于在字符串 str 的指定位置 pos 之后插入子串 newstr,替换随后的 len 个字符。例如:

SELECT INSERT('MySQL字符串函数', 6, 3, '日期') AS str;
str         |
------------+
MySQL日期函数|

以上是MySQL中如何使用REPLACE()函数的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:yisu.com。如有侵权,请联系admin@php.cn删除