MySQL中比like语句更高效的写法locatepositioninstrfind

xiaoxiao2021-02-28  108

1、LIKE       SELECT `column` FROM `table` where `condition` like`%keyword%' 事实上,可以使用 locate(position) 和 instr这两个函数来代替

2、LOCATE语句      SELECT `column` from `table` where locate(‘keyword’,`condition`)>0 3、POSITION语句(LOCATE 的別名 POSITION)       SELECT `column` from `table` where position('keyword' IN `condition`) 4、INSTR语句       SELECT `column` from `table` where instr(`condition`,'keyword')>0      locate、position 和 instr 的差別只是参数的位置不同,同时locate多一个起始位置的参数外,两者是一样的。      mysql> SELECT `column` from `table` where LOCATE(‘bar’, ‘foobarbar’,5); 5、FIND_IN_SET语句       find_in_set(str1,str2) 函数:返回str2中str1所在的位置索引,其中str2必须以","分割开。       mysql> select * from test where find_in_set('name1',name);

转载请注明原文地址: https://www.6miu.com/read-54334.html

最新回复(0)