Home > Database > Mysql Tutorial > body text

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

王林
Release: 2023-09-06 19:01:11
forward
771 people have browsed it

如果子字符串在作为 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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template