本文介绍了从字符串创建MySQL SET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法可以从MySQL中的字符串分隔值创建集合?例如:
Is there a way to create a set from a string of separated values in MySQL? For example:
'快速,棕色,狐狸' => 'the','quick','brown','fox'
'the,quick,brown,fox' => 'the','quick','brown','fox'
一种反向EXPORT_SET,没有固定位.
A sort of inverse EXPORT_SET without the bit fiddeling.
致谢
推荐答案如果您尝试在IN语句中使用集合,而不是拆分字符串,则可以进行如下比较:
If you're trying to use the set in an IN statement, instead of splitting the string, you could do a comparison like:
SELECT * FROM `table` WHERE 'the,quick,brown,fox' REGEXP CONCAT('(^|,)','word','(,|$)');我不确定如果您的数据集很大,那么效率如何,但是它可能比读取临时表并从中进行选择要快.
I'm not sure how efficient this would be if your dataset is large, but it might be faster than reading into and selecting from a temporary table.
更多推荐
从字符串创建MySQL SET
发布评论