Use ESCAPE to define escape characters in SQL.

Source: Internet
Author: User

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:


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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.