Skip to main content

Overview

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. 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):
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.
The above query will show the following 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: