This article will introduce to you how MySQL uses the ESCAPE keyword. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
Escape represents the original semantics of the escape character. The purpose of an escape character is to start a character sequence so that escape The character sequence at the beginning of a character has different semantics than when the character sequence appears alone.
In MySQL, the escape characters start with "//m.sbmmt.com/m/faq/\". Common escape characters in programming are all valid in MySQL and will not be described or discussed here. Here, the function of the ESCAPE keyword is mainly explained through "%" and "_".
%: Match any number of characters.
_: Matches a single character.
If we want to match "%" or "_", we must use "//m.sbmmt.com/m/faq/\" to escape, as follows:
### 查询名字中带明字的用户 > SELECT * FROM user WHERE name LIKE CONCAT("%", "明", "%") ### 查询名字带有%字符的用户 > SELECT * FROM user WHERE name LIKE CONCAT("%", "\%", "%")
ESCAPE keyword The main function is to specify a character to replace the function of "//m.sbmmt.com/m/faq/\".
### 查询名字带有“%”字符的用户 > SELECT * FROM user WHERE name LIKE CONCAT("%", "$%", "%") ESCAPE "$" ### 查询名字带有“_”字符的用户 > SELECT * FROM user WHERE name LIKE CONCAT("%", "a_", "%") ESCAPE "a"
It should be noted that all characters referred to by ESCAPE in the query conditions will replace the role of "//m.sbmmt.com/m/faq/\".
### 假设存在名字为 %a 和 %_ 两个的用户 > SELECT * FROM user WHERE name LIKE "a%_" ESCAPE "a" ### %a %_ > SELECT * FROM user WHERE name LIKE "a%a" ESCAPE "a" ### %a > SELECT * FROM user WHERE name LIKE "a%a_" ESCAPE "a" ### %_
Related recommendations: "mysql tutorial"
The above is the detailed content of How MySQL uses the ESCAPE keyword. For more information, please follow other related articles on the PHP Chinese website!