Usage:
SUBSTRING (Str,pos,len)
SUBSTRING (str from POS for Len)
SUBSTRING (Str,pos)
SUBSTRING (str from POS)
Alias Substr
Intercept string str String that starts at the beginning of the POS length of Len, if you do not set the Len parameter to get all content after POS by default
Note that the index of the string is starting from 1.
If the POS is a negative number, The intercept begins after the string.
1. All data after the interception of POS
The code is as follows |
Copy Code |
mysql> Select substring (' MySQL database ', 2); + ——————————-+ | SUBSTRING (' MySQL database ', 2) | + ——————————-+ | Ysql Database | + ——————————-+ 1 row in Set |
2.3 character data after the interception of POS
The code is as follows |
Copy Code |
mysql> Select substring (' MySQL database ', 2, 3); + ——————————— + | SUBSTRING (' MySQL database ', 2, 3) | + ——————————— + | ysq | + ——————————— + 1 row in Set |
3. See some other examples
The code is as follows |
Copy Code |
mysql> SELECT SUBSTRING (' quadratically ', 5); -> ' ratically ' mysql> SELECT SUBSTRING (' Foobarbar ' from 4); -> ' Barbar ' mysql> SELECT SUBSTRING (' quadratically ', 5,6); -> ' Ratica ' mysql> SELECT SUBSTRING (' Sakila ',-3); -> ' ila ' mysql> SELECT SUBSTRING (' Sakila ',-5, 3); -> ' Aki ' mysql> SELECT SUBSTRING (' Sakila ' FROM-4 for 2); -> ' Ki ' |
Now that I'm here, I'll take a look.
Substring_index
Substring_index (Str,delim,count)
code is as follows |
copy code |
mysql> SELECT substring_index (' www.111cn.net ', '. ', 2); -> ' WWW.111CN ' mysql> SELECT substring_index (' www.111cn.net ', '. ',-2); -> ' 111cn.net ' |