MySQL's InStr function

Source: Internet
Author: User

INSTR (STR,SUBSTR) searches for the specified character (SUBSTR) in a string (STR) and returns the position (INDEX) of the specified character;
STR is searched for the string subs;tr the string you want to search

In the string str, the first position (index) of the string substr appears, the index is calculated from 1, and if not found, returns 0 without returning a negative number.

For example, the name of the query field named "Army" in the name, the traditional method is:

select name from 用户表 where name like `%军%‘;To use the InStr method: select name from 用户表 where instr( ‘name‘,‘军‘ );Or: select name from 用户表 where instr( ‘name‘,‘ 军‘)>0;

The index is only valid for ' keyword% ', does not play a role in the beginning of the% ('%keyword ', '%keyword% '), and the retrieval speed is much faster after changing to InStr ().

InStr function for MySQL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.