This article will walk you through the STRPOS() function with its syntax and a few examples.
The STRPOS() is used to return the position from where the substring (the second argument) is matched with the string (the first argument).
The input and return must be of type string.
- 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.
Case 1: Basic STRPOS() function
In the example below, we will find the ut (substring) position in the computer (string):
We can see that ut is located at the fifth character of the computer:
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:
The result will display the al position of different words:
Updated 11 May 2023
Did this page help you?