May 16, 2021 MySQL
Wildcards are often used in mysql queries, and mysql wildcards and pgsql are different, even regular expressions can be used in mysql. T
his article brings you the use of wildcards in mysql queries.
SQL pattern match:
""" matches a single character, """"""
"%" matches any character, including zero characters
Matching in sql mode, the default is that there is no requirement for the case of letters, and in sqll mode, "
For example:
SELECT * FROM [user] WHERE u_name LIKE ‘%三%’;
SELECT * FROM [user] WHERE u_name LIKE ‘_三_’;
The positive pattern matches:
When using a positive match, use the REGEP and NOT REGEXP operators (or RLIKE and NOT RLIKE, the functions are the same).
The characters involved are:
"." matches any single character.
"""""" For example, ""abc" matches "a", "b" or "c", "a-z" matches any lowercase letter, and ""0-9" matches any number.
"""" means matching zero or more things in front of it. For example, "x" matches any number of "x" characters, "0-9" matches any number of numbers, and "." matches any number of anything.
Note: Regular expressions are case-sensitive, but we can also match two types of writing with a character class. For example, ""aA" matches a lowercase or capital "a" and ""a-zA-Z" matches any letter written in both ways.
In order to locate a pattern so that it must match the beginning or end of the value being tested, use the word " at the beginning of the pattern or "$" at the end of the pattern.
For example:
- Look for names that begin with three
FROM [user] WHERE u_name REGEXP ‘^三’;
- Look for names that end in three
FROM [user] WHERE u_name REGEXP ‘三$’;
- The "repeat n times" operator overrides the previous query:
FROM [user] WHERE u_name REGEXP ‘b{2}$’;
Recommended reading:
MySQL Getting Started tutorial
Original address: 26 o'clock blog s mysql query in the use of wildcards