LOCATE
Description
The LOCATE function is used to find the substring substr in the string str and returns the position index of the first occurrence of substr after the pos position. If the pos parameter is specified, the search starts from that position; if pos is not specified, the search is conducted throughout the entire string str. The position index returned by this function starts counting from 1, and if pos is less than 1, it returns 0.
Parameter Description
- substr (string): The substring to be found.
- str (string): The main string to be searched.
- pos (bigint, optional): The starting position index for the search. The default value is 1.
Return Result
Returns the position index (bigint type) of the first occurrence of substr in str, and returns 0 if not found.
Usage Example
By the above example, you can better understand the usage and functionality of the LOCATE function. In practical applications, the LOCATE function can help you quickly locate and extract specific substrings within a string.