效率 对比
实践:
SELECT LOCATE("45","45,45,u"),FIND_IN_SET("45","45,45,u"),FIND_IN_SET("458","45,45,u");
https://blog.csdn.net/Saropetry/article/details/106496212
LIKE FIND_IN_SET LOCATE
MySQL :: MySQL 8.0 Reference Manual :: 12.8 String Functions and Operators https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_find-in-set
-
Returns a value in the range of 1 to
N
if the stringstr
is in the string liststrlist
consisting ofN
substrings. A string list is a string composed of substrings separated by,
characters. If the first argument is a constant string and the second is a column of typeSET
, theFIND_IN_SET()
function is optimized to use bit arithmetic. Returns0
ifstr
is not instrlist
or ifstrlist
is the empty string. ReturnsNULL
if either argument isNULL
. This function does not work properly if the first argument contains a comma (,
) character.mysql> SELECT FIND_IN_SET('b','a,b,c,d'); -> 2
-
LOCATE(
,substr
,str
)LOCATE(
substr
,str
,pos
)The first syntax returns the position of the first occurrence of substring
substr
in stringstr
. The second syntax returns the position of the first occurrence of substringsubstr
in stringstr
, starting at positionpos
. Returns0
ifsubstr
is not instr
. ReturnsNULL
if any argument isNULL
.mysql> SELECT LOCATE('bar', 'foobarbar'); -> 4 mysql> SELECT LOCATE('xbar', 'foobar'); -> 0 mysql> SELECT LOCATE('bar', 'foobarbar', 5); -> 7
This function is multibyte safe, and is case-sensitive only if at least one argument is a binary string.