Get the App
SLTechnology News&Howtos  ›  Database  › 

How to use the INSTR () function in MySQL

Shulou Source: shulou.com Published: 2022-05-31 10:53:37 10月19日 Update

Editor to share with you how to use the INSTR () function in MySQL, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

INSTR ()

The INSTR (str,substr) function returns the index position of the substring substr in the string str for the first time, and returns 0 if the substring is not found. For example:

Select INSTR ('MySQL string function', 'string') AS index1, INSTR ('MySQL string function', 'date') AS index2, INSTR ('MySQL string function','') AS index3, INSTR ('MySQL string function', null) AS index4;index1 | index2 | index3 | index4 |-+ 6 | 0 | 1 |

In addition, the LOCATE (substr,str) function can also be used to return the index position of the substring substr in the string str for the first time, the only difference from the INSTR (str,substr) function is that the parameters are in reverse order.

The LOCATE (substr,str,pos) function returns the index position where the substring substr first appears in the string str starting from the position pos, for example:

SELECT LOCATE ('sparkling MySQL Server', 5) AS ind;ind |-+ 7 |

FIELD (str,str1,str2,str3, …) The function returns the position of the string str in the subsequent string list, and 0 if it is not found. For example:

SELECT FIELD ('Li Si', 'Zhang San','Li Si', 'Wang Wu') AS ind;ind |-+ 2 |

The FIND_IN_SET (str,strlist) function returns the position of the string str in the list string strlist, where the strlist consists of N substrings separated by commas. For example:

SELECT FIND_IN_SET ('Li Si', 'Zhang San, Li Si, Wang Wu') AS ind;ind |-+ 2 | this is all the content of the article "how to use the INSTR () function in MySQL". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Function character string position Li Si for the first time article index content Zhang San Wang Wu different not much stature then parameters most of which is date more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Huawei NVidia Docker macOS