Home >Database >Mysql Tutorial >Which MySQL functions work like the LOCATE() function?
The MySQL INSTR() and POSITION() functions work similarly to the LOCATE() function. They are both synonyms for the LOCATE() function.
The INSTR() function also returns the position of the first occurrence of the substring after searching from the string. The syntax of INSTR() is as follows -
INSTR(string, substring)
Here, String is the string to be searched by MySQL, and substring is the string to be searched.
mysql> Select INSTR('Ram is a good boy', 'good')As Result; +--------+ | Result | +--------+ | 10 | +--------+ 1 row in set (0.00 sec)
POSITION() function also returns the position of the first occurrence of the substring after searching from the string. The syntax of POSITION() is as follows -
INSTR(substring IN string)
Here, String is the string to be searched by MySQL.
Substring is the string to search for.
'IN' is the keyword.
mysql> Select POSITION('good' in 'Ram is a good boy')As Result; +--------+ | Result | +--------+ | 10 | +--------+ 1 row in set (0.00 sec)
The above is the detailed content of Which MySQL functions work like the LOCATE() function?. For more information, please follow other related articles on the PHP Chinese website!