LOCATE
The first syntax returns the position of the first occurrence of substring substr in string str. The second syntax returns the position of the first occurrence of substring substr in string str, starting at position pos. Returns 0 if substr is not in str. Returns NULL if any argument is NULL.
Analyze Syntax
func.locate(<substr>, <str>, <pos>)
Analyze Examples
func.locate('bar', 'foobarbar')
+------------------------------------+
| func.locate('bar', 'foobarbar') |
+------------------------------------+
| 5 |
+------------------------------------+
func.locate('bar', 'foobarbar', 5)
+------------------------------------+
| func.locate('bar', 'foobarbar', 5) |
+------------------------------------+
| 7 |
+------------------------------------+
SQL Syntax
LOCATE(<substr>, <str>)
LOCATE(<substr>, <str>, <pos>)
Arguments
Arguments | Description |
---|---|
<substr> | The substring. |
<str> | The string. |
<pos> | The position. |
Return Type
BIGINT
SQL Examples
SELECT LOCATE('bar', 'foobarbar')
+----------------------------+
| LOCATE('bar', 'foobarbar') |
+----------------------------+
| 4 |
+----------------------------+
SELECT LOCATE('xbar', 'foobar')
+--------------------------+
| LOCATE('xbar', 'foobar') |
+--------------------------+
| 0 |
+--------------------------+
SELECT LOCATE('bar', 'foobarbar', 5)
+-------------------------------+
| LOCATE('bar', 'foobarbar', 5) |
+-------------------------------+
| 7 |
+-------------------------------+
Last modified April 01, 2024 at 11:19 AM EST: wip (1bb56e9)