Home > Database > Mysql Tutorial > body text

Which MySQL functions work like the LOCATE() function?

WBOY
Release: 2023-09-05 23:41:02
forward
540 people have browsed it

哪些 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)
Copy after login

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)
Copy after login

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)
Copy after login

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)
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!