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 intercept MySQL strings and characters for query

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Let's learn how to intercept MySQL strings and characters for query. I believe you will benefit a lot after reading it. The text is not much in essence. I hope you want to know how to intercept MySQL strings and characters to query this short article.

1. Interception of strings in MySQL

There are special string interception functions in MySQL: two of them are commonly used: substring_index (str,delim,count) and concat

The 1.substring_index (str,delim,count) function is commonly used.

The order in the function parentheses is: the string to be intercepted (such as "aaa_bbb_ccc"), the delimiter (such as "_"), and the position (indicating the number of delimiters, such as "1").

Count is a positive number, so the number starts from the left, and the function returns the string to the left of the count delimiter

Count is negative, so the number starts from the right, and the function returns everything to the right of the count delimiter.

The count can be 0 and the return is empty.

Example: substring_index ("aaa_bbb_ccc", "_", 1), returned as aaa; substring_index ("aaa_bbb_ccc", "_", 2), returned as aaa_bbb; substring_index ("aaa_bbb_ccc", "_",-2), "_", 1), returned as bbb

2.concat is to concatenate several strings

Example: concat ('masks, girls, girls, boys, girls, girls, boys, girls, boys, girls, girls, boys, girls, girls,

Return: mysql

Second, query all the data containing this character according to a field in the table

1.find_in_set:SELECT * FROM user WHERE find_in_set ('Wu', name)

Query all name data in the user table that contains "Wu"

2.REGEXP:SELECT * FROM user WHERE name REGEXP'('Wu'| 'Liu')'

Using rules, query data containing Liu or Wu

After reading this article on how to intercept MySQL strings and characters to query, many readers will certainly want to know more about it. For more industry information, you can follow our industry information section.

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