Fuzzy search escape in SQL

Source: Internet
Author: User

When you want to query special characters such as _ and %, use escape

Select ename from EMP where ename like '% S _ % 'escape s ';

We do not want to search for employees who must have more than one character after S, but remove S. S is used to escape and escape _. Here _ is not a wildcard, but actually _.

Select ename from EMP where ename like '%/_ %' escape '/';

In general, we use a slash (/) to escape, so as to avoid any difference.

1. Use the escape keyword to define the escape character. In mode, when an escape character is placed before a wildcard, the wildcard is interpreted as a common character. For example, to search for a string containing string 5% at any position, use: Where Columna like '% 5/%' escape '/'

2. Escape 'escape _ character 'allows you to search for wildcards in strings rather than using them as wildcards. Escape_character is a character that represents this special purpose before a wildcard. Select * From finances where description like 'gs _ 'escape's' means: for example, if you want to search for a string "g _", then, "_" is used as a wildcard rather than a character. As a result, we will find "Ga", "GB", "GC", rather than "g _". use like 'gs _ 'escape's S' to indicate special usage flag

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: info-contact@alibabacloud.com 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.