为了匹配字符串中的数字,MySQL中的语法如下:select * from yourTab leName where yourColumnName regexp '[0-9]';
要了解上述语法,让我们创建一个表-mysql> create table DemoTable1841
(
Code varchar(20)
);
使用插入命令在表中插入一些记录-mysql> insert into DemoTable1841 values('John231');
mysql> insert into DemoTable1841 values('19876Sam');
mysql> insert into DemoTable1841 values('Carol');
mysql> insert into DemoTable1841 values('67474');
使用select语句显示表中的所有记录-mysql> select * from DemoTable1841;
这将产生以下输出-+----------+
| Code |
+----------+
| John231 |
| 19876Sam |
| Carol |
| 67474 |
+----------+
4 rows in set (0.00 sec)
这是匹配字符串中数字的正则表达式-mysql> select * from DemoTable1841 where Code regexp '[0-9]';
这将产生以下输出-+----------+
| Code |
+----------+
| John231 |
| 19876Sam |
| 67474 |
+----------+
3 rows in set (0.00 sec)