从字符串创建MySQL SET

编程入门 行业动态 更新时间:2024-10-27 03:35:10
本文介绍了从字符串创建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

本文发布于:2023-10-28 02:08:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535194.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   MySQL   SET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!