Home  >  Article  >  Database  >  How to use the REPLACE() function in MySQL

How to use the REPLACE() function in MySQL

WBOY
WBOYforward
2023-06-02 23:25:012725browse

REPLACE()

REPLACE(str,from_str,to_str)The function is used to replace all from_str in the string str with to_str and return the replaced string. For example:

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

In addition, INSERT(str,pos,len,newstr)The function is used to insert the substring newstr after the specified position pos of the string str, replacing the subsequent len ​​characters . For example:

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

The above is the detailed content of How to use the REPLACE() function in MySQL. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete
Previous article:How to batch modify mysqlNext article:How to batch modify mysql