In mysql, locate() is mainly used for case-insensitive string search. It can return the position of the first occurrence of the substring in the string; the syntax is "LOCATE(substring to be searched) String, string[,start])", the parameter "start" is omitted and specifies the starting position of the search. The default value is 1. If the substring is not found in the original string, the locate() function returns 0.
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
MySQL LOCATE() function
#Usage: Case-insensitive string search and returns the first character in the string The position of the first occurrence of the substring
LOCATE() function can return the position of the first occurrence of the substring in the string; if the substring is not found in the original string, Then return 0.
Syntax:
LOCATE(substring, string [,start])
Parameters | Description |
---|---|
substring | Required. Sub string to search in string |
string | Required. The string to search for |
#start | Optional. The starting position of the search. Position 1 is the default value |
#If the specified substring is found in the original string, the return value must be greater than 0.
Usage examples of LOCATE() function
Example 1: Omit the start parameter
LOCATE(字符串1,字符串2)
Return string 1 in string 2 At the first occurrence, as long as string 2 contains string 1, the return value must be greater than 0.
Example 2: Do not omit the start parameter
LOCATE(字符串1,字符串2,start)
Returns the position where string 1 first appears in string 2, starting from the position start Start;
If 0 is returned, it means there is no more
mysql video tutorial]
The above is the detailed content of How to use mysql locate(). For more information, please follow other related articles on the PHP Chinese website!