跳转到内容

第一种语法返回子串 substr 在字符串 str 中首次出现的位置。 第二种语法返回子串 substr 在字符串 str 中从位置 pos 开始首次出现的位置。 如果 str 中不包含 substr,则返回 0。任何参数为 NULL 时返回 NULL。

func.locate(<substr>, <str>, <pos>)
func.locate('bar', 'foobarbar')
┌────────────────────────────────────┐
│ func.locate('bar', 'foobarbar') │
├────────────────────────────────────┤
│ 5 │
└────────────────────────────────────┘
func.locate('bar', 'foobarbar', 5)
┌────────────────────────────────────┐
│ func.locate('bar', 'foobarbar', 5) │
├────────────────────────────────────┤
│ 7 │
└────────────────────────────────────┘
LOCATE(<substr>, <str>)
LOCATE(<substr>, <str>, <pos>)
参数 说明
<substr> 子串。
<str> 字符串。
<pos> 位置。

BIGINT

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 │
└───────────────────────────────┘