webCOMAND

LOCATE()

Return the position of the first occurrence of a substring. 

This function is multi-byte safe, and is case-sensitive only if at least one argument is a binary string.

Prototype

int LOCATE(string substr, string str[, int position])

Parameters

  • substr - The substring to find the position of in str.
  • str - The string or expression to evaluate to a string to search for substr.
  • position - Optional position to start searching from.

Return

Returns the position of the first occurrence of substring substr in string str, where 1 is the first character.  If position is provided, the first occurrence of substring substr in string str, starting at position will be returned.  Returns 0 if substr is not in str.  Returns NULL if any argument is NULL.

Example

SELECT OID, LOCATE(Username, Email) AS UsernamePos FROM User

Related

IN_STR()