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