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