Methods in SQL to determine if a string contains characters

Source: Internet
Author: User

CHARINDEX: Checks if a character (string) is contained in another string, and returns the starting position of the specified expression in the string.

PATINDEX: Checks if a character (string) is contained in another string, returns the starting position of the first occurrence of a pattern in the specified expression, or zero if the pattern is not found in all valid text and character data types. Subscript starting from 1 (the difference is that the latter supports fuzzy matching, the former is a full match)

1.SELECT PATINDEX ('%[^0-9]% ', ' 1235x461 ') results 5
2.SELECT PATINDEX ('%[^0-9]% ', ' 12350461 ') results 0
3.SELECT PATINDEX ('%[0-9]% ', ' SUYLLG0 ') results 7
4.SELECT PATINDEX ('%[0-9]% ', ' SUYLLG01 ') results 7

5.select PATINDEX ('%ter% ', ' interesting data ') Results 3

6.select PATINDEX ('%t_ng% ', ' interesting data ') Results 8

7.SELECT CHARINDEX (' 5 ', ' 1235x461 ') result 4 No, that's 0. The first parameter is the character to be searched (string), the second is the string to be found

8.select charindex (' Test ', ' This test is Test ' COLLATE latin1_general_cs_as) result 0 case-sensitive CS

9.select charindex (' Test ', ' This test is Test ' COLLATE latin1_general_ci_as) result 6 case insensitive CI

(Self-practice and collation of other people's information, do not do business purposes, only to do learning and communication use)

Methods in SQL to determine if a string contains characters

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.