INSTR (STR,SUBSTR)
Returns the first occurrence of a string of str neutron strings. This is the same as locate (), unless the order of the parameters is reversed.
The code is as follows |
Copy Code |
mysql> SELECT INSTR (' Foobarbar ', ' Bar '); -> 4 mysql> SELECT INSTR (' Xbar ', ' foobar '); -> 0 |
LOCATE (SUBSTR,STR), LOCATE (Substr,str,pos)
The first syntax returns the first occurrence of the string substr of the str neutron string. The second syntax returns the first occurrence of the string str neutron string substr, starting at the Pos point. If SUBSTR is not in Str, the return value is 0.
The code is as follows |
Copy Code |
mysql> SELECT LOCATE (' Bar ', ' Foobarbar '); -> 4 mysql> SELECT LOCATE (' Xbar ', ' foobar '); -> 0 mysql> SELECT LOCATE (' Bar ', ' Foobarbar ', 5); -> 7
|
This function supports multibyte characters and is case-sensitive only if at least one argument is a binary string.
POSITION (substr in str)
Returns the position of the substring substr the first occurrence in string str. If substring substr does not exist in STR, the return value is 0:
The code is as follows |
Copy Code |
mysql> SELECT POSITION (' Bar ', ' Foobarbar '); -> 4 mysql> SELECT POSITION (' Xbar ', ' foobar '); -> 0 |
Efficiency test
The code is as follows |
Copy Code |
SELECT * from ' O_soft ' WHERE LOCATE (' d200 ', Tid2) >0 |
MySQL returned a query result that is empty (that is, 0 rows). (Query takes 0.0050 seconds)
The code is as follows |
Copy Code |
SELECT * from ' O_soft ' WHERE INSTR (' d200 ', Tid2) >0 |
MySQL returned a query result that is empty (that is, 0 rows). (Query takes 0.0009 seconds)