Home > Database > Mysql Tutorial > body text

MySQL string interception and interception characters for query

亚连
Release: 2018-05-10 10:30:52
Original
2817 people have browsed it

Use some string interception functions that come with mysql to process the data. The following is the string interception and interception characters I compiled for query.

1. String interception in MySQL
There are special string interception functions in MySQL: there are two commonly used ones: substring_index(str,delim,count ) and concat
1.substring_index(str,delim,count) functions are commonly used.
The order inside the function brackets is: the string to be separated and intercepted (such as: "aaa_bbb_ccc"), the delimiter (such as: "_"), and the position (indicating which delimiter is located, such as: " 1").
If count is a positive number, then counting starts from the left, and the function returns the string to the left of the count-th separator;
If count is a negative number, then counting starts from the right, and the function returns the count-th separator Everything on the right;
count can be 0 and returned is empty.

例子:substring_index("aaa_bbb_ccc","_",1) ,返回为 aaa;
         substring_index("aaa_bbb_ccc","_",2) ,返回为 aaa_bbb;
         substring_index(substring_index("aaa_bbb_ccc","_",-2),"_",1) ,返回为 bbb;
Copy after login

2.concat is to connect several strings
Example: concat('m','y','s','q','l');
Return: mysql
2. Query all data containing this character based on a field in the table
1.find_in_set: SELECT * FROM user WHERE find_in_set('Wu', name);
Query all data in the user table whose name contains "Wu"
2.REGEXP: SELECT * FROM user WHERE name REGEXP '('WHERE'|'Liu')';
Use regular rules, Query the data containing Liu or Wu

The above is the MySQL string interception and interception characters I compiled for query. I hope it will be helpful to everyone in the future

Related articles:

php basic mysql

php mysql continuous operation

How to use transaction automation in mysql connection pool Recycling (with code)

The above is the detailed content of MySQL string interception and interception characters for query. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template