MySQL 类似 SQL 的语句“%[^0-9]%”不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16951156/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 17:51:09  来源:igfitidea点击:

SQL like statement "%[^0-9]%" not working

mysqlmysql-workbench

提问by Jia-Luo

I have a table.

我有一张桌子。

USER TABLE Columns:
    user_name (varchar)
    age       (int)
    address   (varchar)
    telephone (varchar)

I want to seach for user whose address field contains digits.

我想搜索地址字段包含数字的用户。

I tried the following sql statement in MySQL Workbench:

我在 MySQL Workbench 中尝试了以下 sql 语句:

SELECT * FROM user WHERE address LIKE '%[^0-9]%';

However, it did not work. Can anyone help me out here?

但是,它不起作用。有人可以帮我从这里出去吗?

Thanks in advance.

提前致谢。

采纳答案by Brad Christie

I believe you're looking for REGEXP:

我相信你正在寻找REGEXP

SELECT   *
FROM     user
WHERE    address REGEXP '.*[^0-9].*'

Exampleof finding addresses without numbers

查找没有数字的地址的示例

回答by gkovacs90

You should remove the ^character from the brackets:

您应该^从括号中删除字符:

LIKE '%[0-9]%'

LIKE '%[0-9]%'

It doesn't want to be a regex, it is the [charlist]wildcard

它不想成为正则表达式,它是[charlist]通配符

回答by Jrf

select * from user where first_name REGEXP '^[0-9].*'

This gives you all records in your user table where the first name starts with numbers 0-9.

这将为您提供用户表中的所有记录,其中名字以数字 0-9 开头。

回答by Sushanth --

'%[^0-9]%'

Will search for the column that has %[^0-9]%as text

将搜索具有%[^0-9]%文本的列

It won't do a Regex on it

它不会对它做正则表达式

Try

尝试

'.[^0-9].'   // That performs regex