让我们首先创建一个表-
mysql> create table DemoTable1908 ( Code text );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1908 values('MySQL(1)Database'); mysql> insert into DemoTable1908 values('MongoDB 2 Database'); mysql> insert into DemoTable1908 values('MySQL(3)Database'); mysql> insert into DemoTable1908 values('SQL Server(10)Database'); mysql> insert into DemoTable1908 values('MySQL 8 Database');
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1908;
这将产生以下输出-
+------------------------+ | Code | +------------------------+ | MySQL(1)Database | | MongoDB 2 Database | | MySQL(3)Database | | SQL Server(10)Database | | MySQL 8 Database | +------------------------+ 5 rows in set (0.00 sec)
这是在REGEXP子句中转义括号并仅显示带()的括号值的查询-
mysql> select * from DemoTable1908 where Code regexp '^MySQL[(][0-9][)]Database';
这将产生以下输出-
+------------------+ | Code | +------------------+ | MySQL(1)Database | | MySQL(3)Database | +------------------+ 2 rows in set (0.00 sec)