Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use SQL statements to intercept strings in MySQL

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail how to use SQL statements to intercept strings in MySQL. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.

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

Column:

SELECT LEFT (201809 / 04)

Results: 2018

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

SELECT RIGHT (February, 201809) month

Results: 09

3. SUBSTRING (name,5,3) intercepts name. This field only intercepts the following 3 characters from the fifth character.

SELECT SUBSTRING ('Chengdu financing Department', 5Pol 3)

Result: business department

4. SUBSTRING (name,3) intercepts the name field from the third character, followed by all the characters

SELECT SUBSTRING (Chengdu financing Department, 3)

Result: financing Division

5. SUBSTRING (name,-4) intercepts the fourth character position (reciprocal) of the name field from beginning to end.

SELECT SUBSTRING (Chengdu financing Department,-4)

Result: capital business department

6. SUBSTRING (name,-4Power2) intercepts the fourth character position (reciprocal) of the name field, and only intercepts the next two characters.

SELECT SUBSTRING ('Chengdu financing Department',-4jin2)

Result: capital management

Note: we notice 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 the second'.' All previous characters

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

Results: www.baidu

8. Substring_index ('www.baidu.com','.',-2) intercepts all characters after the second'.'(reciprocal)

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

Results: baidu.com

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

SELECT SUBSTR (Chengdu financing Department, 1, CHAR_LENGTH (Chengdu financing Department)-3)

Result: Chengdu financing

On how to use SQL statements in MySQL to intercept strings to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report