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)

更新於: 19-11-2020

114 次瀏覽

開啟你的 職業生涯

完成課程,獲取認證

開始學習
廣告
© . All rights reserved.