Replace MYSQL query characters with SQL statements

Source: Internet
Author: User
Replace can be used to replace the characters in mysql, as shown in the following example.

Replace can be used to replace the characters in mysql, as shown in the following example.

The Code is as follows:

Mysql> 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.

Replace and RegEx to replace characters

The Code is as follows:


UPDATE 'table _ name' SET 'field _ name' = replace ('field _ name', 'From _ str', 'to _ str ') WHERE 'field _ name' LIKE '% from_str %'

Note:
Table_name -- table name
Field_name -- field name
From_str -- string to be replaced
To_str -- string to be replaced

The following are two SQL batch replacement statements run today. For more information, see!

The Code is as follows:

UPDATE boblog_blogs SET content = replace (content, '[mycode = xml]', '[mycode = html]');

In the query table boblog_blogs, replace the [mycode = xml] character in the content field with [mycode = html].

The Code is as follows:
UPDATE boblog_blogs SET content = replace (content, '[// mycode]', '[/mycode]');

In the query table boblog_blogs, replace the character [// mycode] In the content field with [/mycode].

The Code is as follows:
UPDATE boblog_blogs SET htmlstat = 0 where htmlstat = 1

Because the regular expression can be used to replace mysql characters, the speed is not as high as that for direct replacement.

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.