How can I manage the start position of searching in MySQL LOCATE() function?


As we know that by default searching in LOCATE() function starts from beginning. We can manage the start position by giving an argument to specify the position from which we want to start the search in string. Following example will demonstrate it −

Example

mysql> Select LOCATE('good','Ram is a good boy. Is Ram a good boy?',11)As Result;

+--------+
| Result |
+--------+
|     29 |
+--------+

1 row in set (0.00 sec)

In the above example, we have given the value 11 as the argument for position. It means that MySQL will start searching from 11th position.

Updated on: 03-Feb-2020

79 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements