Replace () can directly replace and display data in mysql. If you check and update the replace data, we need to work with the update statement. Next I will introduce you to the operation method.
Recently I changed the code highlighting plug-in of my blog. Previously I used SyntaxHighlighter:
Code Format:
<Pre class = "brush: php; gutter: true">
// Code area
......
</Pre> switch to Crayon Syntax Highlighter:
<Pre class = "lang_php decode_true">
// Code area
......
</Pre> the highlighted area of the Code is different, and many articles need to be modified. Well, mysql certainly has a replacement function, so I found the replace () function of mysql:
Replace () function Syntax:
Update [table_name] set [field_name] = replace ([field_name], '[string_to_find]', '[string_to_replace]'); instance:
The Code is as follows: |
Copy code |
Mysql> select replace ('www. bKjia. c0m', 'www ', 'map '); + ---------------------------------------- + | REPLACE ('www. bKjia. c0m', 'www ', 'map') | + ---------------------------------------- + | Map. bKjia. c0m | + ---------------------------------------- +
|
1 row in set (0.00 sec). Therefore, a function can replace () to easily solve the problem:
The Code is as follows: |
Copy code |
UPDATE wp_posts SET post_content = REPLACE (post_content, '<pre class = "brush: php; gutter: true">', '<pre class = "lang_php decode_true"> '); |
We can also use mysql replace
The Code is as follows: |
Copy code |
Replace into table (id, name) values ('1', 'A'), ('2', 'bb ') |
This statement inserts two records into the table.