The use of replace in mySQL
- 2020-05-14 05:03:49
- OfStack
Example description of mysql replace:
UPDATE tb1 SET f1=REPLACE(f1, 'abc', 'def');
REPLACE(str,from_str,to_str)
All strings from_str that appear in the string str are replaced by to_str, and this string is returned
This function is useful for batch replacement of illegal keywords in data! Here are some examples:
Example 1: UPDATE BBSTopic SET tcontents = replace(replace(tcontents,'die,'),' death ',' death ') where tcontents like '%die%' or tcontents like '% '
Example 2: UPDATE typetable SET type_description=REPLACE(type_description,'360','// www.ofstack.com ');
mysql replace usage
1.replace into
replace into table (id,name) values('1','aa'),('2','bb')
This statement inserts two records into the table table. If the primary key id is 1 or 2 does not exist
Is equivalent to
insert into table (id,name) values('1','aa'),('2','bb')
If the same value exists, no data is inserted
2.replace(object,search,replace)
Replace all search in object with replace
select replace('www.ofstack.com','w','Ww')---
>
WwWwWw.ofstack.com
Example: replace aa in the name field of the table table with bb
update table set name=replace(name,'aa','bb')
We often use MySQL replace function, the following for you to introduce the use of MySQL replace function in detail, I hope you learn MySQL replace function can be enlightened.
Recently, I have been studying CMS. MySQL replace function of mysql needs to be used in data conversion. Here is a brief introduction 1.
Let's say you want to replace abc in tb1 with def in f1
UPDATE tb1 SET f1=REPLACE(f1, 'abc', 'def');
REPLACE(str,from_str,to_str)
All the strings from_str that appear in the string str are replaced by to_str and return the string:
mysql
>
SELECT REPLACE('www.mysql.com', 'w', 'Ww');
-
>
'WwWwWw.mysql.com'
This function is multi-byte safe.
Example:
UPDATE `dede_addonarticle` SET body = REPLACE ( body,
'
<
/td
>
',
'' );
UPDATE `dede_addonarticle` SET body = REPLACE ( body,
'
<
/tr
>
',
'' );
UPDATE `dede_addonarticle` SET body = REPLACE ( body,
'
<
tr
>
',
'' );
UPDATE `dede_archives` SET title= REPLACE ( title,
'ocean 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')
This statement inserts two records into the table table.
2.replace(object, search,replace)
Replace all search in object with replaceselect replace(' www.ofstack.com ', 'w', 'Ww')--
>
WwW wWw.ofstack.com
Example: replace aa in the name field of table table with bbupdate table set name=replace(name, 'aa', 'bb')
supplement
SELECT * FROM `goods_table` WHERE Context like "%Welcome%Store%" ORDER BY `goods_table`.`GoodsId` DESC
update goods_table set Context = replace(Context, 'Welcome to Yahoo Store !', 'Welcome to Our Store !');