使用 REGEXP 匹配每條記錄後的可選行尾?
我們先建立一個表 -
mysql> create table DemoTable(EmployeeCode varchar(100)); Query OK, 0 rows affected (0.56 sec)
使用 insert 命令在表中插入一些記錄 -
mysql> insert into DemoTable values('EMPLOYEE:100 John Smith');
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable values('EMPLOYEE:16537 Chris Brown');
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable values('EMPLOYEE:100 David Miller');
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable values('EMPLOYEE:100 23432 David Miller');
Query OK, 1 row affected (0.20 sec)使用 select 語句顯示錶中的所有記錄 -
mysql>; select *from DemoTable;
這將生成以下輸出 -
+---------------------------------+ | EmployeeCode | +---------------------------------+ | EMPLOYEE:100 John Smith | | EMPLOYEE:16537 Chris Brown | | EMPLOYEE:100 David Miller | | EMPLOYEE:100 23432 David Miller | +---------------------------------+ 4 rows in set (0.00 sec)
以下是對 “EMPLOYEE:100 23432 David Miller” 中的 100 後的可選行尾進行匹配的查詢,例如 23434 -
mysql> select *from DemoTable where EmployeeCode REGEXP "EMPLOYEE:100([^0-9]|$)";
這將生成以下輸出 -
+---------------------------------+ | EmployeeCode | +---------------------------------+ | EMPLOYEE:100 John Smith | | EMPLOYEE:100 David Miller | | EMPLOYEE:100 23432 David Miller | +---------------------------------+ 3 rows in set (0.00 sec)
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP