使用正則表示式返回特定的 MySQL 字串


我們首先建立一個表 −

mysql> create table DemoTable649 (Value text);
Query OK, 0 rows affected (0.68 sec)

使用 insert 命令在表中插入一些記錄 −

mysql> insert into DemoTable649 values('1903');
Query OK, 1 row affected (0.08 sec)
mysql> insert into DemoTable649 values('9321010');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable649 values('983032023393');
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable649 values('1234567892');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable649 values('989898989');
Query OK, 1 row affected (0.20 sec)

使用 select 語句顯示錶中的所有記錄 −

mysql> select *from DemoTable649;

這將產生以下輸出 −

+--------------+
| Value        |
+--------------+
| 1903         |
| 9321010      |
| 983032023393 |
| 1234567892   |
| 989898989    |  
+--------------+
5 rows in set (0.00 sec)

以下查詢用於返回使用正則表示式的特定 MySQL 字串 −

mysql> select *from DemoTable649 where Value REGEXP '[0-9]{11}';

這將產生以下輸出 −

+--------------+
| Value        |
+--------------+
| 983032023393 |
+--------------+
1 row in set (0.00 sec)

更新於: 23-08-2019

93 瀏覽過

開啟你的職業生涯

完成課程獲得認證

立即開始
廣告