VeloDB Cloud
SQL Manual
Functions
string-functions
locate

locate

Description

Syntax:

INT LOCATION (VARCHAR substrate, VARCHAR str [, INT pos]]

This function returns the location where substr appears in str (counting from 1). If the third argument pos is specified, it will look for substr starting from where pos indicates. If substr is not found, it will 0.

Example

mysql> SELECT LOCATE('bar', 'foobarbar');
+----------------------------+
| locate('bar', 'foobarbar') |
+----------------------------+
|                          4 |
+----------------------------+

mysql> SELECT LOCATE('xbar', 'foobar');
+--------------------------+
| locate('xbar', 'foobar') |
+--------------------------+
|                        0 |
+--------------------------+

mysql> SELECT LOCATE('bar', 'foobarbar', 5);
+-------------------------------+
| locate('bar', 'foobarbar', 5) |
+-------------------------------+
|                             7 |
+-------------------------------+

Keywords

LOCATE