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 implement an intercept string function in MySQL

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

How to implement an intercept string function in MySQL? I believe many inexperienced people don't know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Function:

1. Intercept the string from the left

Left (str, length)

Description: left (intercepted field, intercepted length)

Example: select left (content,200) as abstract from my_content_t

2. Intercept the string from the right

Right (str, length)

Description: right (intercepted field, intercepted length)

Example: select right (content,200) as abstract from my_content_t

3. Intercept the string

Substring (str, pos)

Substring (str, pos, length)

Description: substring (intercepted field, which bit to intercept)

Substring (intercepted field, which bit to intercept, intercept length)

Example: select substring (content,5) as abstract from my_content_t

Select substring (content,5200) as abstract from my_content_t

(note: if the number of digits is negative, such as-5, it is the length from the last digit to the end of the string or truncated.)

4. Intercept a string by keyword

Substring_index (str,delim,count)

Description: substring_index (intercepted fields, keywords, number of keyword occurrences)

Example: select substring_index ("blog.chinabyte.com", "." , 2) as abstract from my_content_t

Results: blog.chinabyte

(note: if the number of times the keyword appears is negative, such as-2, it is reciprocal from the back to the end of the string)

Results: chinabyte.com

After reading the above, have you mastered how to implement an intercept string function in MySQL? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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