[TOC]
The role of the escape
Escape is used for wildcard escape
For example, if you want to search for a string containing a wildcard character, it will be interpreted as a wildcard character, rather than a normal character, and will definitely not be able to find it
The first character immediately after the escape character is treated as a normal character rather than a wildcard character
The escape usage
Let’s say there are five pieces of data, as shown above
Query Example 1
Let’s say we want to query for % in the username field
In the right mind, we could do this
The wrong sample
select * from tablename where username like '%%%'
Copy the code
The idea is that the first and third % are wildcards, and the second % is a normal character, but written this way, the computer doesn’t know, and it will treat all % as wildcards
The result of this query is not what we need
The second % can then be identified with escape
The correct sample
select * from tablename where username like '%#%%' escape '#'
Copy the code
Escape specifies that the first character after the # character is considered a normal character
Query Example 2
Select * from username where username = ‘username’;
select * from tablename where username like '%#[%' escape '#'
Copy the code
Follow me for more content