What is the function of LOCATE in MySQL?

In MySQL, the LOCATE function is used to find the position of one string within another string. It returns the position of the first occurrence of the first string in the second string, and returns 0 if not found. The syntax of the LOCATE function is:

LOCATE(substr, str)

In this case, substr is the string to be searched for, and str is the string to search within. For example:

SELECT LOCATE('or', 'hello world');  

The above query will return 3, as ‘or’ appears for the first time at the 3rd position in ‘hello world’.

Leave a Reply 0

Your email address will not be published. Required fields are marked *