要获取以5个数字字符开头的电子邮件地址,可选的解决方案是使用REGEXP-select *from yourTableName where yourColumnName regexp "^[0-9]{5}";
让我们首先创建一个表-mysql> create table DemoTable
(
UserEmailAddress varchar(100)
);
使用插入命令在表中插入一些记录-mysql> insert into DemoTable values('6574John@gmail.com');
mysql> insert into DemoTable values('Carol23456@gmail.com');
mysql> insert into DemoTable values('98989Chris_45678@gmail.com');
mysql> insert into DemoTable values('Mike12@gmail.com');
mysql> insert into DemoTable values('56453Adam@gmail.com');
使用select语句显示表中的所有记录-mysql> select *from DemoTable;
这将产生以下输出-+----------------------------+
| UserEmailAddress |
+----------------------------+
| 6574John@gmail.com |
| Carol23456@gmail.com |
| 98989Chris_45678@gmail.com |
| Mike12@gmail.com |
| 56453Adam@gmail.com |
+----------------------------+
5 rows in set (0.00 sec)
以下是选择所有以5个数字字符开头的电子邮件地址的查询-mysql> select *from DemoTable where UserEmailAddress regexp "^[0-9]{5}";
这将产生以下输出-+----------------------------+
| UserEmailAddress |
+----------------------------+
| 98989Chris_45678@gmail.com |
| 56453Adam@gmail.com |
+----------------------------+
2 rows in set (0.00 sec)