Mysql truncate string

Source: Internet
Author: User
1. string truncation: left (str, length) mysqlselectleft (linuxidc.com, 3); + rows + left (linuxidc.com, 3) + ----------------------- + SQL + --------------------- + 2. string truncation: right (str, length) mysqlselectright (linuxidc.com, 3); + --

1. string truncation: left (str, length) mysqlselectleft ('linuxidc. com ', 3); + ----------------------- + left ('linuxidc. com ', 3) + ------------------------- + SQL + ----------------------- + 2. string truncation: right (str, length) mysqlselectright ('linuxidc. com ', 3); + --

1. string truncation: left (str, length) mysql> select left ('linuxidc. com ', 3); + ----------------------- + | left ('linuxidc. com ', 3) | + ----------------------- + | SQL | + ------------------------- + 2. string truncation: right (str, length) mysql> select right ('linuxidc. com ', 3); + ------------------------ + | right ('linuxidc. com ', 3) | + ------------------------ + | com | + -------------------------- + 3. string truncation: substring (str, pos); subst Ring (str, pos, len) 3.1 starts from the position of the string's 4th characters until the end. Mysql> select substring ('linuxidc. com ', 4); + ---------------------------- + | substring ('linuxidc. com ', 4) | + -------------------------- + | study.com | + -------------------------------- + 3.2 starts from the string's position of 4th characters and takes only 2 characters. Mysql> select substring ('linuxidc. com ', 4, 2); + --------------------------------- + | substring ('linuxidc. com ', 4, 2) | + ------------------------------- + | st | + ------------------------------------- + 3.3 starts from the string's position of 4th characters (reciprocal) until the end. Mysql> select substring ('linuxidc. com ',-4); + ----------------------------- + | substring ('linuxidc. com ',-4) | + ------------------------------- + |. com | + ------------------------------- + 3.4 starts from the string's 4th character position (reciprocal) and takes only 2 characters. Mysql> select substring ('linuxidc. com ',-4, 2); + ---------------------------------- + | substring ('linuxidc. com ',-4, 2) | + ------------------------------------ + |. c | + -------------------------------- + We noticed that in the substring (str, pos, len) function, pos can be negative, but len cannot be negative. 4. String truncation: substring_index (str, delim, count) 4.1 intercepts all the characters before the second. Mysql> select substring_index ('www .linuxidc.com ','. ', 2); + ---------------------------------------------- + | substring_index ('www .linuxidc.com ','. ', 2) | + ------------------------------------------------ + | www | + -------------------------------------------- + 4.2 intercepts the second one '. all characters After '(reciprocal. Mysql> select substring_index ('www .linuxidc.com ','. ',-2); + ----------------------------------------------- + | substring_index ('www .linuxidc.com ','. ',-2) | + ----------------------------------------------- + | com.cn | + Limit + 4.3 If the value specified by the delim parameter is not found in the string, returns the entire string mysql> select substring_index ('www .linuxidc.com ','. coc ', 1); + ------------------------------------------------- + | substring_index ('www .linuxidc.com ','. coc ', 1) | + ------------------------------------------------- + | www.linuxidc.com | + ----------------------------------------------- +

Original article address: mysql intercepts strings and thanks to the original author for sharing them.

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.