Creating a MySQL SET's from a string

前端 未结 4 1604
我寻月下人不归
我寻月下人不归 2021-01-18 21:29

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\'

A

4条回答
  •  無奈伤痛
    2021-01-18 21:58

    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.

提交回复
热议问题