Use the pattern match in like search conditions for SQL queries

Source: Internet
Author: User

The like keyword searches for the string, date, or time value that matches the specified pattern. For more information, see data types. The like keyword uses the regular expression to include the pattern to be matched by the value. The mode contains the string to be searched. A string can contain any combination of four wildcard characters.

Wildcard Description
% Any string containing zero or more characters.
_ Any single character.
[] Specifies any single character in the range (for example, [a-f]) or set (for example, [abcdef.
[^] Any single character that is not in the specified range (for example, [^ a-f]) or set (for example, [^ abcdef.

Use single quotes to enclose wildcards and strings. For example:

    • like 'mc % 'searches all strings starting with MC (for example, mcbadden ).

    • like '% Inger' searches all strings ending with the letter Inger (such as ringer and Stringer ).
    • like '% en %' searches all strings (such as Bennet, green, and mcbadden) that contain letters en at any position ).
    • like '_ heryl' searches for names (such as Cheryl and Sheryl) of all six letters ending with heryl ).
    • like '[Ck] ARS [EO] n' searches for the following strings: Carsen, Karsen, Carson, and karson (such as Carson ).
    • like '[M-Z] Inger' searches for all names (such as ringer) ending with string Inger, starting with any single letter from m to Z ).
    • like'm [^ C] %' searches for all names (such as macfeather) Starting with m, and the second letter is not C ).

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.