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 a Senior Software Engineer at Naukri.com. He passed out of Delhi College of Engineering in 2016 and likes to play Foosball. He loves traveling and is an exercise freak. His expertise includes Java, PHP, Python, Databases, Design and Architecture.