Pular para o conteúdo

A primeira sintaxe retorna a posição da primeira ocorrência da substring substr na string str. A segunda sintaxe retorna a posição da primeira ocorrência da substring substr na string str, a partir da posição pos. Retorna 0 se substr não estiver em str. Retorna NULL se algum argumento for 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>)
Argumentos Descrição
<substr> A substring.
<str> A string.
<pos> A posição.

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