I have been researching CMS recently and I need to use MySQL’s replace function when converting data. Here is a brief introduction!
For example, if you want to replace abc in the f1 field in table tb1 with def
UPDATE tb1 SET f1=REPLACE(f1, 'abc', 'def');
REPLACE(str,from_str,to_str) In the characters All occurrences of the string from_str in the string str are replaced by to_str, and then this string is returned: SELECT REPLACE('www.mysql.com', 'w', 'Ww'); -> ; 'WwWwWw. mysql.com' This function is multi-byte safe.
Example: UPDATE `dede_addonarticle` SET body = REPLACE ( body, '', '' ); UPDATE `dede_addonarticle` SET body = REPLACE ( body, '' , '' ); UPDATE `dede_addonarticle` SET body = REPLACE ( body, '
', '' ); UPDATE `dede_archives` SET title= REPLACE ( title, 'Dayang News- ', '' ); UPDATE `dede_addonarticle` SET body = REPLACE ( body, '../../../../../../', 'http://special.dayoo.com /meal/' );
mysql replace
Usage 1.replace intoreplace into table (id,name) values('1','aa'),('2','bb') The function of this statement is Insert two records into the table. 2.replace(object, search,replace) Replace all occurrences of search in object with replaceselect replace('www.163.com','w','Ww')--->WwW wWw.163. com
Example: Replace aa in the name field in the table with bbupdate table set name=replace(name,'aa','bb')
The above is the content of using the replace function of mysql to replace the string, more For more related articles, please pay attention to the PHP Chinese website (www.php.cn)!
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn