当 MySQL 中的列值以 2 个元音字母开头时,检索记录
我们先创建一个表 −
mysql> create table DemoTable664 (CityName varchar(100)); Query OK, 0 rows affected (0.89 sec)
使用插入命令在表中插入一些记录 −
mysql> insert into DemoTable664 values('Springfield'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable664 values('Austin'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable664 values('Franklin'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable664 values('OAKLAND'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable664 values('Anchorage'); Query OK, 1 row affected (0.18 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable664;
这将生成以下输出 −
+-------------+ | CityName | +-------------+ | Springfield | | Austin | | Franklin | | OAKLAND | | Anchorage | +-------------+ 5 rows in set (0.00 sec)
以下是使用 RLIKE/REGEXP 模式和显示每当列值以 2 个元音字母开头时的记录的查询 −
mysql> select *from DemoTable664 where CityName RLIKE '^[aeiouAEIOU][aeiouAEIOU]';
这将生成以下输出 −
+----------+ | CityName | +----------+ | Austin | | OAKLAND | +----------+ 2 rows in set (0.00 sec)
广告