Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use like and instr in mysql

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you about how to use like and instr in mysql. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Use the like keyword

Select * from tbl1 where name like'% Red%'

Conduct a fuzzy search through the'% keyword%'.

Fuzzy searches with the'% keyword g do not use indexes. For example, an idiom dictionary is an idiom arranged in alphabetical order, for example, you want to look up the idiom that contains the word red, but if the red is not at the beginning, how to look it up, because you can only turn the page without the scarlet letter at the beginning. This is equivalent to doing like operation, full table scan, without any shortcuts.

Use the instr function

Select * from tbl1 where instr (name, 'red') > 0

Compare the keyword to the beginning of the name field, and return > 1 if the keyword is the same as the first character, or several characters in the order

In the case of fuzzy search, instr is more efficient than like, because instr looks directly from the beginning, finds and returns, only for the keyword being searched, while like lies in the table field itself. For example, "123F45" and "12F345" both satisfy% F%. If you replace F with other strings, like needs to match more content, and the amount of computation is much larger than instr.

This is how like and instr are used in mysql shared by Xiaobian. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report