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

Vue mobile terminal determines the direction of finger sliding on the screen

The vue mobile terminal determines the direction ...

How to restore single table data using MySQL full database backup data

Preface When backing up the database, a full data...

Use of Linux file command

1. Command Introduction The file command is used ...

Detailed explanation of the steps of using ElementUI in actual projects

Table of contents 1. Table self-sorting 2. Paging...

Linux unlink function and how to delete files

1. unlink function For hard links, unlink is used...

Briefly describe the difference between MySQL and Oracle

1. Oracle is a large database while MySQL is a sm...

How to control the proportion of Flex child elements on the main axis

background Flex layout achieves alignment and spa...

Install MySQL in Ubuntu 18.04 (Graphical Tutorial)

Tip: The following operations are all performed u...

Detailed steps for deploying Tomcat server based on IDEA

Table of contents Introduction Step 1 Step 2: Cre...

How to set npm to load packages from multiple package sources at the same time

Table of contents 1. Build local storage 2. Creat...

Example analysis of mysql user rights management

This article describes the MySQL user rights mana...

Server stress testing concepts and methods (TPS/concurrency)

Table of contents 1 Indicators in stress testing ...