MySQL:选择列包含列表元素的行

时间:2021-04-02 01:42:29

I am trying to select all rows from a table where column contains an element from a list: Something like

我试图从列中包含列表中的元素的表中选择所有行:类似于

Select * from `table` where `column` (contains anything from {£,$,%,^,&,...,/})

This is basically an illegal character check.

这基本上是非法的角色检查。

Can anyone help?

有人可以帮忙吗?

Thanks

谢谢

4 个解决方案

#1


9  

For MySQL you may use REGEXP or RLIKE to check specific column for pattern matching. In your case following example might work:

对于MySQL,您可以使用REGEXP或RLIKE检查特定列以进行模式匹配。在您的情况下,以下示例可能有效:

SELECT * FROM `table` WHERE `column` REGEXP '[\£\$\%\^\&]';

#2


0  

You can use LIKE for pattern matching,

您可以使用LIKE进行模式匹配,

SELECT  *
FROM    `table`
WHERE   `column` LIKE '%£%' OR
        `column` LIKE '%$%' OR
        `column` LIKE '%\%%' OR
        `column` LIKE '%&%'

#3


0  

If I understood this correctly you want all rows which have non alphanumeric characters ie other than digits and alphabets

如果我理解正确,你想要所有具有非字母数字字符的行,即数字和字母以外的行

SELECT * FROM `table` WHERE `column` REGEXP '^[^a-zA-Z0-9]+$'

The ^ inside [ ] charcter class implies negation while outside at the beginning of regular expression specifies starting of column value. $ imples ending of string value

^ inside [] charcter类意味着否定,而在正则表达式的开头外部指定列值的开始。 $ implements结束字符串值

#4


0  

SELECT * FROM table WHERE column LIKE '%\%%' OR column LIKE '%$%' OR column LIKE '%&%';

...etc. '%char%' means that there is char somewhere, '%char' means that char is at the end of string, 'char%' means that it is at the beginning. '%\%%' means that searched char (%) is a special char used by mysql and '\' is necessary.

...等等。 '%char%'表示某处存在char,'%char'表示char位于字符串的末尾,'char%'表示它位于开头。 '%\ %%'表示搜索的char(%)是mysql使用的特殊字符,'\'是必需的。

#1


9  

For MySQL you may use REGEXP or RLIKE to check specific column for pattern matching. In your case following example might work:

对于MySQL,您可以使用REGEXP或RLIKE检查特定列以进行模式匹配。在您的情况下,以下示例可能有效:

SELECT * FROM `table` WHERE `column` REGEXP '[\£\$\%\^\&]';

#2


0  

You can use LIKE for pattern matching,

您可以使用LIKE进行模式匹配,

SELECT  *
FROM    `table`
WHERE   `column` LIKE '%£%' OR
        `column` LIKE '%$%' OR
        `column` LIKE '%\%%' OR
        `column` LIKE '%&%'

#3


0  

If I understood this correctly you want all rows which have non alphanumeric characters ie other than digits and alphabets

如果我理解正确,你想要所有具有非字母数字字符的行,即数字和字母以外的行

SELECT * FROM `table` WHERE `column` REGEXP '^[^a-zA-Z0-9]+$'

The ^ inside [ ] charcter class implies negation while outside at the beginning of regular expression specifies starting of column value. $ imples ending of string value

^ inside [] charcter类意味着否定,而在正则表达式的开头外部指定列值的开始。 $ implements结束字符串值

#4


0  

SELECT * FROM table WHERE column LIKE '%\%%' OR column LIKE '%$%' OR column LIKE '%&%';

...etc. '%char%' means that there is char somewhere, '%char' means that char is at the end of string, 'char%' means that it is at the beginning. '%\%%' means that searched char (%) is a special char used by mysql and '\' is necessary.

...等等。 '%char%'表示某处存在char,'%char'表示char位于字符串的末尾,'char%'表示它位于开头。 '%\ %%'表示搜索的char(%)是mysql使用的特殊字符,'\'是必需的。