Only part of the data method is updated at MySQL database update

Source: Internet
Author: User

Requirements: Update the URL in the most characters of '-1 ' to '-5 ', the previous content remains unchanged

The contents of the URL column are as follows:Http://h5game.ecs.cedarmg.com/a/captal/dispther.do?deviceid=b-01-1

SELECT * from Qrmsgwhere url like '%1 '

http://h5game.ecs.cedarmg.com/c/captal/dispther.do?deviceid=b-01- 1

need to put this last -1 Change into -5

Here's how it works:

UPDATE qrmsg SET url= CONCAT (substring_index (URL, '-', ' 2 '), '-5 ') where URL like '%1 '

select* from qrmsg WHERE url like '% 5 '

Http://h5game.ecs.cedarmg.com/ca/capital/dispather.do?deviceid=b-01-5


The following functions are used:

1 , Substring_index (Str,delim,count)

Str: the string to process

Delim: Separators

Count: Count

Example: str=www.google.com

Substring_index (str, '. ', 1)

The result is:www

Substring_index (str, '. ', 2)

The result is:www.google

that is , if count is a positive number, then it is the left-to-right, and the left of the nth delimiter.

Conversely, if it is a negative number, it is All the content from the right to the right of the nth delimiter, such as:

Substring_index (str, '. ',-2)

The result is:google.com

Someone will do for, if I ah in the middle of Google what to do?

very simple, two directions:

1 , right-hand side of the second delimiter, and from the left of the first delimiter of the number:

Substring_index (Substring_index (str, '. ', -2),'. ' , 1);

2 , you know!

2 , concat is to concatenate several strings that can be multiple oh.

Concat (' wo ', ' lin ', ' Xue ', ' bin ')

The result is wolinxuebin.



Reference blog:

http://blog.csdn.net/wolinxuebin/article/details/7845917

Only part of the data method is updated at MySQL database update

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.