Skip to main content
Version: V1.0.0

LOCATE

Declaration

LOCATE(substr,str)
LOCATE(substr,str,pos)

Description

The first syntax returns the first occurrence of the substring substr in the string str. The second syntax returns the first occurrence of the substring substr in the string str, starting at the position pos. If substr is not found in str, the return value is 0.

Example

SELECT LOCATE('bar', 'foobarbar'), LOCATE('xbar', 'foobar'), LOCATE('bar', 'foobarbar',5);
+----------------------------+--------------------------+------------------------------+
| LOCATE('bar', 'foobarbar') | LOCATE('xbar', 'foobar') | LOCATE('bar', 'foobarbar',5) |
+----------------------------+--------------------------+------------------------------+
| 4 | 0 | 7 |
+----------------------------+--------------------------+------------------------------+
1 row in set (0.001 sec)