![]() |
The SQL Server PATINDEX() function returns the starting index of the first occurrence of a pattern in a string or a specified expression. It returns an integer value indicating the starting position of the first occurrence of the pattern in the expression. If the pattern is not found it returns zero, if either pattern or expression is NULL, it returns NULL. SyntaxThe SQL Server PATINDEX() function syntax is:
ParametersPATINDEX() function takes two parameters, and both are required.
Applicable to:The function PATINDEX() is applicable to the following databases.
SQL Server PATINDEX() Function ExamplesLet’s look at some examples of the PATINDEX() function in SQL server. Learning the PATINDEX() function with examples will help to understand the function better. Example 1In this example, we will find the first occurrence of ‘ek’ in the string ‘GeeksforGeeks’. Query: SELECT PATINDEX('%ek%', 'GeeksforGeeks');
Output: Example 2In this example, we are finding the first occurrence of the letter ‘z’ in the string ‘GeeksforGeeks’. Query: SELECT PATINDEX('%[z]%', 'GeeksforGeeks');
Output: It returns 0 because the given string does not contain the letter ‘z. Example 3In this example, we are finding the first occurrence of the symbol in the string ‘How are you?’. Query: SELECT position = PATINDEX('%[^ 0-9A-z]%', 'How are you?'); Output: |
Reffered: https://www.geeksforgeeks.org
Databases |
Related |
---|
|
![]() |
![]() |
|
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 11 |