Aller au contenu

La première syntaxe renvoie la position de la première occurrence de la sous-chaîne substr dans la chaîne str. La seconde syntaxe renvoie la position de la première occurrence de la sous-chaîne substr dans la chaîne str, en commençant à la position pos. Renvoie 0 si substr ne figure pas dans str. Renvoie NULL si l’un des arguments est 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>)
Arguments Description
<substr> La sous-chaîne.
<str> La chaîne.
<pos> La position.

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