What happens if the substring is there for more than one time in the string given as the arguments of LOCATE() function?

MySQLMySQLi Database

In case if the substring is there for more than one time in the string then MySQL LOCATE() function will return the position of the first occurrence of the substring.

Example

mysql> Select LOCATE('good','Ram is a good boy. Is Ram a good boy?')As Result;
+--------+
| Result |
+--------+
|     10 |
+--------+
1 row in set (0.00 sec)

As we can see that the substring ‘good’ is in the string for two times. The first occurrence is at position 10 and another occurrence is at position 29. MySQL returns the position of the first occurrence.

raja
Published on 20-Feb-2018 07:04:07
Advertisements