mysql的内置函数instr(filed,str),作用是返回str子字符串在filed字符串的第一次出现的位置。当instr(filed,str)=0时,表示子符串str不存在于字符串filed中,因此可以用来实现mysql中的模糊查询,与like用法类似。如下:
// 1、instr()函数,#{name}为参数
select id,name from test where instr(name,#{name})>0 
// 2、like
select id,name from test where name like concat('%',#{name},'%')

instr()详细用法如下:

instr(filed,str) > 0 ⇒ file like '%str%'
instr(filed,str) = 1 ⇒ file like  'str%'
instr(filed,str) = 0 ⇒ file not like  '%str%'
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐