Home  >  Article  >  Database  >  What happens if a substring appears multiple times in the string given as an argument to the LOCATE() function?

What happens if a substring appears multiple times in the string given as an argument to the LOCATE() function?

王林
王林forward
2023-09-06 19:01:11762browse

如果子字符串在作为 LOCATE() 函数参数给出的字符串中出现多次,会发生什么情况?

If a substring appears multiple times in a string, the MySQL LOCATE() function returns the position of the first occurrence of the substring.

Example

mysql> Select LOCATE('good','Ram is a good boy. Is Ram a good boy?')As Result;
+--------+
| Result |
+--------+
|     10 |
+--------+
1 row in set (0.00 sec)

We can see that the substring "good" appears twice in the string. The first time appears at position 10 and the other time at position 29. MySQL returns the position of the first occurrence.

The above is the detailed content of What happens if a substring appears multiple times in the string given as an argument to the LOCATE() function?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete