MySQL 正则表达式仅显示带有字符串或数字与字符串混合的记录。忽略仅有数字的记录
为此,您可以使用 REGEXP。以下是语法 −
select yourColumnName from yourTableName where yourColumnName REGEXP '[a−zA&minu;Z]';
我们创建一个表格 −
mysql> create table demo41 −> ( −> name varchar(40) −> ); Query OK, 0 rows affected (0.64 sec)
借助插入命令向表格中插入一些记录 −
mysql> insert into demo41 values('John Smith34')
−> ;
Query OK, 1 row affected (0.13 sec)
mysql> insert into demo41 values('John Smith');
Query OK, 1 row affected (0.11 sec)
mysql> insert into demo41 values('9234John Smith');
Query OK, 1 row affected (0.14 sec)
mysql> insert into demo41 values('john smith');
Query OK, 1 row affected (0.23 sec)
mysql> insert into demo41 values('98775');
Query OK, 1 row affected (0.15 sec)使用 select 语句从表格中显示记录 −
mysql> select *from demo41;
将产生以下输出 −
+----------------+ | name | +----------------+ | John Smith34 | | John Smith | | 9234John Smith | | john smith | | 98775 | +----------------+ 5 rows in set (0.00 sec)
以下是 MySQL regexp 的查询 −
mysql> select name from demo41 where name REGEXP '[a−zA−Z]';
将产生以下输出 −
+----------------+ | name | +----------------+ | John Smith34 | | John Smith | | 9234John Smith | | john smith | +----------------+ 4 rows in set (0.00 sec)
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP