mysql 函数

it2023-04-09  74

find_in_set(str1, str2)

1)  select find_in_set('b', 'a,b,c,d'); 

     返回str2(逗号分隔)中str1的个数,比如b个数为1

2)  select * from srv_contract where FIND_IN_SET(id, '10000,10001,10002'); 

     等价于 in 

3)select * from srv_contract where FIND_IN_SET(#{id}, '10000,10001,10002') > 0 

     或者

     select * from srv_contract where FIND_IN_SET(#{id}, '10000,10001,10002')

     如果FIND_IN_SET返回大于0,则返回全部记录,否则返回0条记录,可用做全部返回或者不返回的开关

最新回复(0)