Home > Database > Mysql Tutorial > body text

MySQL interception and split string function usage example_MySQL

WBOY
Release: 2016-11-30 23:59:43
Original
1337 people have browsed it

The example in this article describes the usage of MySQL interception and splitting string functions. Share it with everyone for your reference, the details are as follows:

First of all, the code is as follows:

SELECT SUBSTRING_INDEX(checkid,'-',-1) FROM `check` WHERE checkid = 'c-11065-50'


How to get 11065:

The code is as follows:

SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(checkid,'-',-2),'-',1) FROM check WHERE checkid = 'c-11065-50'


Or:

The code is as follows:

SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(checkid,'-',2),'-',-1) FROM check WHERE checkid = 'c-11065-50'


It seems a bit complicated, so let’s do something more complicated:

The following is the combined usage. For example, we want to intercept 13 in content_13-11220-1. The simplest one is:

The code is as follows:

SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING(commentid,9), '-', 1), '-',-1) FROM check WHERE commentid = 'content_13-11220-1'


We found that we need to call the function three times here. Is there any method that can be called twice? So we can write like this:

The code is as follows:

SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(commentid, '-', 1), '_',-1) FROM check WHERE commentid = 'content_13-11220-1'


In this way, the function can be executed once less. When we run enough data, the speed will be obvious.

For more MySQL functions, please refer to the MySQL function encyclopedia: http://www.bitsCN.com/article/42906.htm

Readers who are interested in more MySQL-related content can check out the special topics of this site: "A Summary of Commonly Used MySQL Functions", "A Complete Collection of MySQL Log Operation Skills", "A Summary of MySQL Transaction Operation Skills", "A Complete Collection of MySQL Stored Procedure Skills" and " Summary of MySQL database lock related skills》

I hope this article will be helpful to everyone’s MySQL database planning.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template