从字符串创建MySQL SET [英] Creating a MySQL SET's from a string

查看:173
本文介绍了从字符串创建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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆