Skip to content

LOCATE

  • substr: This is the substring to be located. It’s a string of characters that you want to find within another string.
  • str: This represents the string in which the search will be conducted. It is the main string where you are looking for the specified substring.
  • pos: This represents the position where the search starts. By default, the search starts at the beginning of the string. If a position is specified, the search starts from that position in the string.
SELECT LOCATE('bar', 'foobarbar');
5

The LOCATE function in MySQL is used to find the position of the first occurrence of a substring in a string. In this example it returns 5, which indicates that the first occurrence of the substring ‘bar’ in the string ‘foobarbar’ starts at the 5th position.