Wildcard characters, escape characters, and the use of [numbers in SQL] (Downmoon)

Source: Internet
Author: User

A description of the search for wildcard-wildcard
You can search for wildcard characters. There are two ways to specify characters that are commonly used as wildcards:

Use the Escape keyword to define an escape character. In a pattern, the wildcard is interpreted as a normal character when the escape character is placed before a wildcard. For example, to search for a string containing the string 5% anywhere, use:
WHERE ColumnA like '%5/%% ' ESCAPE '/'

In the LIKE clause above, the leading and trailing percent sign (%) is interpreted as a wildcard character, and the percent semicolon after the slash (/) is interpreted as% of characters.

Only the wildcard character itself is included in the square brackets ([]). To search for a dash (-) instead of specifying a search scope, specify the dash as the first character in square brackets:
WHERE ColumnA like ' 9[-]5 '

The following table shows the use of wildcard characters enclosed in square brackets.

symbols meaning
Like ' 5[%] ' 5%
Like ' 5% ' 5 string followed by 0 or more characters
Like ' [_]n ' _n
Like ' _n ' An, in, on (and)
Like ' [A-CDF] ' A, B, C, D, or F
Like ' [-ACDF] ' -, A, C, D, or F
Like ' [[] ' [
Like '] ' ]

Second, the example description:

Look in the table Personalmember to find records in the Strloginname field that contain "[".


You can use three statements:
1,
Select strloginname,* from Personalmember where strloginname like '%\[% ' escape '

2. (description "\" and "/" can be combined with escape keyword as escape character)
Select strloginname,* from Personalmember where strloginname like '%/[% ' escape '/'

3,
Select strloginname,* from dbo. Personalmember where CHARINDEX (' [', Strloginname) >0



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.