Home  >  Article  >  Database  >  Which MySQL functions work like the LOCATE() function?

Which MySQL functions work like the LOCATE() function?

WBOY
WBOYforward
2023-09-05 23:41:02560browse

哪些 MySQL 函数的工作方式与 LOCATE() 函数类似?

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 -

The syntax of INSTR()

INSTR(string, substring)

Here, String is the string to be searched by MySQL, and substring is the string to be searched.

Example

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 -

The syntax of POSITION()

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.

Example

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!

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