您需要为此使用REGEXP。语法如下
SELECT *FROM yourTableName WHERE yourColumnName REGEXP '[a-zA-Z]';
为了理解这个概念,让我们创建一个表。创建表的查询如下
mysql> create table SelectNonNumericValue -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> UserId varchar(100) -> );
使用insert命令在表中插入一些记录。查询如下
mysql> insert into SelectNonNumericValue(UserId) values('123John'); mysql> insert into SelectNonNumericValue(UserId) values('58475Carol98457Taylor24'); mysql> insert into SelectNonNumericValue(UserId) values('199575Sam124'); mysql> insert into SelectNonNumericValue(UserId) values('Mike2456'); mysql> insert into SelectNonNumericValue(UserId) values('1000'); mysql> insert into SelectNonNumericValue(UserId) values('1001'); mysql> insert into SelectNonNumericValue(UserId) values('10293Bob'); mysql> insert into SelectNonNumericValue(UserId) values('David'); mysql> insert into SelectNonNumericValue(UserId) values('2456');
使用select语句显示表中的所有记录。查询如下
mysql> select *from SelectNonNumericValue;
以下是输出
+----+-------------------------+ | Id | UserId | +----+-------------------------+ | 1 | 123John | | 2 | 58475Carol98457Taylor24 | | 3 | 199575Sam124 | | 4 | Mike2456 | | 5 | 1000 | | 6 | 1001 | | 7 | 10293Bob | | 8 | David | | 9 | 2456 | +----+-------------------------+ 9 rows in set (0.00 sec)
这是选择非数字值的查询
mysql> select *from SelectNonNumericValue WHERE UserId REGEXP '[a-zA-Z]';
以下是忽略数值的输出
+----+-------------------------+ | Id | UserId | +----+-------------------------+ | 1 | 123John | | 2 | 58475Carol98457Taylor24 | | 3 | 199575Sam124 | | 4 | Mike2456 | | 7 | 10293Bob | | 8 | David | +----+-------------------------+ 6 rows in set (0.00 sec)