Replace MySQL character replacement function SQL statement sharing (Regular Expression judgment)

Source: Internet
Author: User

CopyCode The Code is as follows: Update dede_addonsoft set dxylink = Replace (dxylink, '.zip ', '.rar') where aid> 45553;

Copy codeThe Code is as follows: Update 'table _ name' set field = replace(field,'.rar','.7z ');

Table_name: name of the table to be queried,
Field: field name in the table,
Replace(field,'.rar', '.7z');: Regular Expression matching. Replace. rar in the field with. 7z.

MySQL Regular Expression replacement, character replacement method

The two SQL statements are both character replacement and easy 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 ';

Replace string with the MySQL replace Function

We often use the MySQL replace function. The following describes the usage of the MySQL replace function in detail, hoping to enlighten you in learning the MySQL replace function.

I recently studied CMS and used MySQL replace function during data conversion. Here I will briefly introduce it.

For example, you want to replace the ABC of the F1 field in Table tb1 with Def.

Update tb1 set F1 = Replace (F1, 'abc', 'def ');

Replace (STR, from_str, to_str)
All the from_str strings in the STR string are replaced by to_str, and the following string is returned:
Mysql> select Replace ('www .mysql.com ', 'w', 'ww ');
-> 'Wwwwww .mysql.com'
This function is multi-byte secure.

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,
'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', 'A'), ('2', 'bb ')
This statement inserts two records into the table.
2. Replace (object, search, replace)
Replace all search objects with replaceselect Replace ('www .163.com ', 'w', 'ww') ---> WWW www.163.com

For example, replace AA in the Name field of the table with bbupdate table set name = Replace (name, 'AA', 'bb ')

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.