The replace MYSQL character substitution function sql statement shares the of regular judgment

  • 2020-05-13 03:33:48
  • OfStack


Update dede_addonsoft SET dxylink=REPLACE(dxylink, '.zip', '.rar') where aid > 45553;

 
update `table_name` set field = replace(field,'.rar','.7z'); 

table_name: the name of the table to query,
field: field name in table,
replace (field, 'rar', '7 z'); : regular match, replace.rar in the field field with.7z

MySQL regular expression replacement, character replacement method

SQL, both character substitutions, are easier to use.

update comment set url=IF(url REGEXP 'test.yahoo.com.cn',REPLACE(url,'www1.sohu.com','www.sina.com'),REPLACE(url,'www2.yahoo.com','www.sina.com')) where 1=1;

update comment set author_url=REPLACE(author_url,'sohu','sina') where author_url REGEXP 'www.sohu.com';

The MySQL replace function replaces the string

We often use MySQL replace function, the following is a detailed introduction to the use of MySQL replace function, 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 of f1 in tb1 with def

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:
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 table table.
2.replace(object, search,replace)
Replace all search in object with replaceselect replace('www. 163.com ','w','Ww')-- > WwW wWw.163.com

Example: replace aa in the name field of table table with bbupdate table set name=replace(name,'aa','bb')

Related articles: