LOCATE()
LOCATE(substr
,str
,pos
)
Returns the position of the first occurrence of
substr
in the string
str
. If the parameter
pos
is passed, the search begins at
position pos
. If
substr
is not found in
str
, a value of 0
is returned. This code returns the values
5
and 11
, because the first function call returns
the first encounter of the word “unit,” while the second one only
starts to search at the seventh character, and so returns the second
instance:
SELECT LOCATE('unit', 'Community unit'); SELECT LOCATE('unit', 'Community unit' 7);