Skip to content

Latest commit

 

History

History
38 lines (28 loc) · 979 Bytes

File metadata and controls

38 lines (28 loc) · 979 Bytes

locate

description

Syntax

INT locate(VARCHAR substr, VARCHAR str[, INT pos])

返回 substr 在 str 中出现的位置(从1开始计数,按「字符」计算)。如果指定第3个参数 pos,则从 str 以 pos 下标开始的字符串处开始查找 substr 出现的位置。如果没有找到,返回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 |
+-------------------------------+

keyword

LOCATE