LOCATE
Descriptionβ
Returns the position of substr in str (counting from 1). If the third parameter pos is specified, the position of substr is searched from the string starting with the pos subscript. If not found, 0 is returned
Syntaxβ
LOCATE ( <substr> , <str> [, <pos> ] )
Parametersβ
Parameter | Description |
---|---|
substr | The substring to be searched |
str | The string to be searched |
pos | If this parameter is specified, the position of substr is searched from the string starting with the pos subscript |
Return valueβ
The position of substr in str (counting from 1)
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 |
+----------------------------+--------------------------+-------------------------------+