STRPOS
9min
This article will walk you through the STRPOS() function with its syntax and a few examples.
Overview
The STRPOS() is used to return the position from where the substring (the second argument) is matched with the string (the first argument).
Syntax
|
ο»Ώ
The input and return must be of type string.
π‘Special cases:
- Returns NULL if there are no input rows or NULL values.
- If the substring is not found in the string, then the STRPOS() function will return 0.
Examples
Case 1: Basic STRPOS() function
In the example below, we will find the ut (substring) position in the computer (string):
Select strpos
|
ο»Ώ
We can see that ut is located at the fifth character of the computer:
Output
|
ο»Ώ
Case 2: STRPOS() function using column
We have a listofwords table where it stores the word data.
Create a Table
|
ο»Ώ
Display the Table
|
ο»Ώ
The above query will show the following table:
The listofwords Table
|
ο»Ώ
The following query will display the words and a position of a specific substring = βalβ using the STRPOS() function:
Select strpos
|
ο»Ώ
The result will display the al position of different words:
Output
|
ο»Ώ
ο»Ώ


Updated 11 May 2023
Did this page help you?
Yes
No