Substring string intercept function usage in MySQL

Source: Internet
Author: User

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 '

Related Article

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.