MySQL intercepts the sql statement of the string function

MySQL intercepts the sql statement of the string function

1. left(name,4) intercepts the 4 characters on the left

List:

SELECT LEFT(201809,4) 年

Results: 2018

2. right (name, 2) intercepts the 2 characters on the right

SELECT RIGHT(201809,2) 月份

Result: 09

3. SUBSTRING(name,5,3) intercepts the name field starting from the fifth character and only intercepts the next 3 characters

SELECT SUBSTRING('成都融資事業部',5,3)

Results: Division

4. SUBSTRING(name,3) intercepts the name field starting from the third character and all subsequent characters

SELECT SUBSTRING('成都融資事業部',3)

Results: Financing Division

5. SUBSTRING(name, -4) starts from the 4th character position (counting down) of the name field and continues until the end

SELECT SUBSTRING('成都融資事業部',-4)

Result: Investment Division

6. SUBSTRING(name, -4, 2) starts from the 4th character position (countdown) of the name field and only takes the next 2 characters.

SELECT SUBSTRING('成都融資事業部',-4,2)

Results:

Note: We noticed that in the function substring(str,pos,len), pos can be negative, but len ​​cannot be negative.

7. substring_index('www.baidu.com', '.', 2) intercepts all characters before the second '.'

SELECT substring_index('www.baidu.com', '.', 2)

Results: www.baidu

8. substring_index('www.baidu.com', '.', -2) intercepts all characters after the second '.' (counting down)

SELECT substring_index('www.baidu.com', '.', -2)

Result: baidu.com

9. SUBSTR(name, 1, CHAR_LENGTH(name)-3) intercepts the name field and removes all characters except the last three digits of the name field

SELECT SUBSTR('成都融資事業部', 1, CHAR_LENGTH('成都融資事業部')-3)

Result: Chengdu Financing

Summarize

The above is the MySQL SQL statement for intercepting string functions introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Usage instructions for the Mysql string interception function SUBSTRING
  • MySQL interception and split string function usage examples
  • Mysql string interception and obtaining data in the specified string
  • mysql intercepts the content between two specified strings
  • Usage of MySQL intercepted string function substring_index
  • Summary of MySQL string interception related functions
  • MySQL implements string interception graphic tutorial

<<:  Ubuntu 16.04 installation tutorial under VMware 12

>>:  How to write elegant JS code

Recommend

The latest graphic tutorial of mysql 8.0.16 winx64 installation under win10

In order to download this database, it takes a lo...

Implementation of MySQL Multi-version Concurrency Control MVCC

Table of contents What is MVCC MVCC Implementatio...

MAC+PyCharm+Flask+Vue.js build system

Table of contents Configure node.js+nvm+npm npm s...

Detailed explanation of setting resource cache in nginx

I have always wanted to learn about caching. Afte...

MySQL 5.7.18 version free installation configuration tutorial

MySQL is divided into installation version and fr...

Learn the basics of nginx

Table of contents 1. What is nginx? 2. What can n...

A practical record of checking and processing duplicate MySQL records on site

Table of contents Preface analyze Data Total Repe...

Example of using UserMap in IMG

usemap is an attribute of the <img> tag, use...

Detailed explanation of where the image pulled by docker is stored

20200804Addendum: The article may be incorrect. Y...

How to use async and await correctly in JS loops

Table of contents Overview (Loop Mode - Common) D...

Implementation example of Docker rocketmq deployment

Table of contents Preparation Deployment process ...

A Brief Analysis on the Time Carrying Problem of MySQL

The default time type (datetime and timestamp) in...