开发者

Check if a string contains numbers

开发者 https://www.devze.com 2023-01-07 12:00 出处:网络
How do I check if a string in a MySQL field contains a number then delete them? Example table: tbl_tags

How do I check if a string in a MySQL field contains a number then delete them?

Example table:

tbl_tags
 -------------
| id | tag    |
 -------------
| 1  | hello 开发者_C百科 |
| 2  | hello2 |
| 3  | 2hello |
| 4  | hel3lo |
 -------------

The only way I can think of is to do each number individually and use LIKE '%1%' OR LIKE '%2%' etc. But there must be an easier way?


Check out the MySQL Regex methods. Something like the following should work.

SELECT * FROM table WHERE tag REGEXP '[0-9]'


SELECT * 
FROM clients
WHERE name REGEXP '^[[:digit:]]+$'
ORDER BY `clients`.`country_id` DESC 
LIMIT 0 , 30

this is the answer if you're looking for strings with only digits

0

精彩评论

暂无评论...
验证码 换一张
取 消