MySQL根据带分隔符的子字符串选择带有LIKE或REGEX的列字符串 [英] MySQL select column string with LIKE or REGEX based on sub-string with delimiters
本文介绍了MySQL根据带分隔符的子字符串选择带有LIKE或REGEX的列字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须将列值与用户输入的数字进行比较.列中的字符串格式为8|5|12|7|
I have to compare a column value with a user input numbers. The string in the column is in the format 8|5|12|7|
现在,我需要将用户输入值2
,5
,3
与该列值进行比较
Now, I need to compare a user input values 2
,5
,3
with this column value
当我将LIKE运算符用作'%2|%'
时,我通过与列值|12|
匹配获得了输出.
When I use LIKE operator as '%2|%'
I got the output by matching with column value |12|
如何使用Regular Expression
或其他任何方式匹配字符串?
How do I match the string by using Regular Expression
or any other way?
推荐答案
如果我理解正确的问题,那么要确保您获得2|..
或..|2|..
或|2
,您需要添加or
条款
If I understand the question correct, then to make sure that you get 2|..
or ..|2|..
or |2
, you need to add or
clauses
where col like '%|2|%'
or col like '2|%'
or col like '%|2'
or col='2'
这篇关于MySQL根据带分隔符的子字符串选择带有LIKE或REGEX的列字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文