Skip to content

POSITION

  • substr: This is a substring that is to be found in the source string. It represents the sequence of characters that you want to locate within the string.
  • str: This is the source string where the substring ‘substr’ will be searched. This represents the string that the function will sift through to find the specified sequence.
SELECT POSITION('world' IN 'hello world') as Position;
+----------+
| Position |
+----------+
| 7 |
+----------+

The POSITION function in MySQL is used to find the position of a substring in a string. The example code returns the position of ‘world’ in ‘hello world’. As ‘world’ starts at the 7th character, the output is 7.