效率 对比
实践:
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
Nif the stringstris in the string liststrlistconsisting ofNsubstrings. 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. Returns0ifstris not instrlistor ifstrlistis the empty string. ReturnsNULLif 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
substrin stringstr. The second syntax returns the position of the first occurrence of substringsubstrin stringstr, starting at positionpos. Returns0ifsubstris not instr. ReturnsNULLif any argument isNULL.mysql> SELECT LOCATE('bar', 'foobarbar'); -> 4 mysql> SELECT LOCATE('xbar', 'foobar'); -> 0 mysql> SELECT LOCATE('bar', 'foobarbar', 5); -> 7This function is multibyte safe, and is case-sensitive only if at least one argument is a binary string.

浙公网安备 33010602011771号