
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
LOCATE Function with Multiple Substring Occurrences
In case if the substring is there for more than one time in the string then MySQL LOCATE() function will return 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)
As we can see that the substring ‘good’ is in the string for two times. The first occurrence is at position 10 and another occurrence is at position 29. MySQL returns the position of the first occurrence.
Advertisements