MySQL Position is an inbuilt function in MySQL. It returns the position of the first occurrence of a substring in a string. However, if the substring does not exist then it returns 0. Moreover, the function performs a case-insensitive search (uppercase and lowercase characters are the same). In this article, we will discuss the MySQL Position Function.
This function is an alias of MySQL Locate Function.
POSITION (substring IN string)
The MySQL Position Function expects two parameters. The description of the parameters is as follows:
- substring: The first parameter is the substring you want to search in the string.
- string: The second parameter is the string in which you need to search.
- start: The third and optional parameter is the start point. By default, the start point is 1.
The function returns the position of
mysql> SELECT POSITION("com" IN "concatly.com") as position; +----------+ | position | +----------+ | 10 | +----------+
In the above example, we search for first occurrence of the substring “com” in “concatly.com”. The function returns the position of the first occurrence.
Vishesh is currently working as an Intermediate Software Engineer with Orion Health, New Zealand. He graduated with a Masters in Information Technology from the University of Auckland in 2021. With more than 4 years of work experience, his expertise includes Java, Python, Machine Learning, PHP, Databases, Design and Architecture.