Use of replace () to replace string functions in MySQL

Source: Internet
Author: User

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.

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.