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.