Use ESCAPE to define escape characters in SQL.
Use ESCAPE to define ESCAPE characters
When the LIKE keyword is used for fuzzy search, "%", "_", and "[]" appear separately, and are considered as wildcards. To check whether there are percent (%), underscore (_), or square brackets ([]) characters in a column of the character data type, you need to tell the DBMS, consider the characters in the LIKE criterion as actual values rather than wildcards. The keyword ESCAPE allows you to determine an ESCAPE character, telling DBMS that the character following the ESCAPE character is considered as the actual value. The following expression:
LIKE '% M %' ESCAPE 'M'
The ESCAPE keyword defines the ESCAPE Character "M", telling DBMS to use the Second Percentile (%) in the search string "% M %" as the actual value, rather than the wildcard. Of course, the first percentile (%) is still considered as a wildcard, so the strings that meet this query condition are all strings ending with %.
Similarly, the following expression:
LIKE 'AB & _ %' ESCAPE '&'
At this time, the escape character "&" is defined, and the character that follows "&" in the search string, that is, "_" is regarded as the actual character value, rather than the wildcard character. "%" In the expression is still processed as a wildcard. The query condition of this expression is all strings starting with "AB.
I hope this article will help you. Thank you for your support for this site!