LOCATE

Returns the first position of the given search string.

Syntax

LOCATE (needle, haystack)
LOCATE (needle, haystack, startpos)

Arguments

Info

This function is identical to INSTR but with the arguments reversed.

Return Type

Integer position, one-indexed. 0 if not found.

Examples

+---------------------+
| locate('i', 'ohai') |
+---------------------+
|                   4 |
+---------------------+

memsql> select locate('z', 'ohai');
+---------------------+
| locate('z', 'ohai') |
+---------------------+
|                   0 |
+---------------------+

memsql> select locate('i', 'ohaiohai', 6);
+----------------------------+
| locate('i', 'ohaiohai', 6) |
+----------------------------+
|                          8 |
+----------------------------+
Was this article useful?