MySQL two trick to handle strings: Substring_index,concat

Source: Internet
Author: User

MySQL two trick to handle strings: Substring_index,concat

I've been dealing with strings in the database lately, and we've found that they're used to go with these two functions:

  1, Substring_index (Str,delim,count)

  STR: The string to be processed

  Delim: Delimiter

  Count: Count

Example: str=

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, from the right of the second delimiter to the right of all, and then the left number of the first delimiter left:

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

2, you know!

  2,concat is a couple of strings that can be multiple oh.

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

The result is wolinxuebin.

MySQL two trick to handle strings: Substring_index,concat

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.