简体   繁体   中英

MYSQL search if a string contains special characters?

I need to search table field contains special characters. I found a solution given here something like:

SELECT * 
FROM `tableName` 
WHERE `columnName` LIKE "%#%" 
OR `columnName` LIKE "%$%" 
OR (etc.)

But this solution is too broad. I need to mention all the special characters. But I want something which search something like:

SELECT *
FROM `tableName`
WHERE `columnName` LIKE '%[^a-zA-Z0-9]%'

That is search column which contains not only az, AZ and 0-9 but some other characters also. Is it possible with MYSQL

Use regexp

SELECT *
FROM `tableName`
WHERE `columnName` REGEXP '[^a-zA-Z0-9]'

This would select all the rows where the particular column contain atleast one non-alphanumeric character.

or

REGEXP '[^[:alnum:]]'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM