top of page
CerebroSQL

LOCATE

База данных: MySQL

68747470733a2f2f7374796c65732e7265646469746d656469612e636f6d2f74355f32716d366b2f7374796c65

Syntax:
LOCATE(substr,str), LOCATE(substr,str,pos)

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.

URL: https://dev.mysql.com/doc/refman/8.0/en/string-functions.html

Example

mysql> SELECT LOCATE('bar', 'foobarbar');
-> 4
mysql> SELECT LOCATE('xbar', 'foobar');
-> 0
mysql> SELECT LOCATE('bar', 'foobarbar', 5);
-> 7

bottom of page