MySQL updates some of the contents of a string field

Source: Internet
Author: User

What should I do if I need MySQL to update the field to re-section data instead of all the data? Here are a few ways to update some of the data in the MySQL field in two scenarios for your reference.

MySQL updates some of the data in the field in the first case:

Update tab SET A = concat (substring (a,1,3), ' BBB ');

Starting from a 1 characters to take 3 characters, plus ' BBB ', and then write a, if the original value of a is ' 123aaa ', then the update is ' 123BBB '.

MySQL updates some of the data in the field in the second case:

1.Mysql Fuzzy query:

SELECT * FROM table where num like '%a% ';
The query has a string of 2. MySQL updates some data for field values:

We may encounter a request to modify the value of one of the fields in the database to another, so you might think of update immediately. For example:

Replace all of the values in field a with 1 with 2.
The SQL statement is written like this: Update table set a=2 where a=1;

So what if we're going to talk about the 1 in the field a value, and replace it with 2?
For example: a=2211, now to replace 2222, is to change 1 to 2
The SQL statement reads: Update table Set A=replace (A, ' 1 ', ' 2 ');

MySQL updates some of the contents of a string field

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.