MySQL 正则表达式仅显示包含字符串或字符串与数字混合的记录。仅忽略数字记录

mysqlmysqli database

为此,您可以使用 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)

使用 insert 命令向表中插入一些记录 −

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 正则表达式的查询 −

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)

相关文章