IN 运算符的逗号分隔参数,MySQL
我有一张表,其中以下查询工作正常:
select *
from session_actions
where action_type IN ('login_failed','channel_recorded')
现在我期待类似以下的内容:
select *
from session_actions
where action_type IN ('login_failed,channel_recorded')
如您所见,我想为 IN
运算符提供一个逗号分隔的参数,但它不可能
如何将此逗号分隔的字符串转换为 IN
运算符可接受的参数列表?
I have a table in which the following query works fine:
select *
from session_actions
where action_type IN ('login_failed','channel_recorded')
Now I'm looking forward to some thing like the following:
select *
from session_actions
where action_type IN ('login_failed,channel_recorded')
As you see I want to give the IN
operator one single comma separated parameter, but it is not possible
How can I convert this comma separated string into a list of parameters which is acceptable to IN
operator?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能正在寻找 FIND_IN_SET() 功能。
示例小提琴
You might be looking for FIND_IN_SET() function.
SAMPLE FIDDLE
我尝试了
FIND_IN_SET
,但速度非常慢。从那时起,我宁愿使用 haystack REGEXP CONCAT('[[:<:]]', Needle, '[[:>:]]') 。I tried
FIND_IN_SET
but it was super slow. I rather usehaystack REGEXP CONCAT('[[:<:]]', needle, '[[:>:]]')
since then.