效率 对比

实践:

 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

  • FIND_IN_SET(str,strlist)

    Returns a value in the range of 1 to N if the string str is in the string list strlist consisting of N 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 type SET, the FIND_IN_SET() function is optimized to use bit arithmetic. Returns 0 if str is not in strlist or if strlist is the empty string. Returns NULL if either argument is NULL. 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 string str. The second syntax returns the position of the first occurrence of substring substr in string str, starting at position pos. Returns 0 if substr is not in str. Returns NULL if any argument is NULL.

    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.

 

 

posted @ 2023-05-25 09:56  papering  阅读(7)  评论(0编辑  收藏  举报