返回仅为数值的行的 MySQL 查询?\n
使用 REGEXP 仅返回数字行。我们首先创建一个表 -
mysql> create table DemoTable -> ( -> StudentId varchar(100) -> ); Query OK, 0 rows affected (0.51 sec)
使用插入命令向表中插入一些记录 -
mysql> insert into DemoTable values('John74747');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable values('8494575Carol');
Query OK, 1 row affected (0.19 sec)
mysql> insert into DemoTable values('985755645');
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable values('Carol-9032');
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable values('101');
Query OK, 1 row affected (0.17 sec)使用 select 语句显示表中的所有记录 -
mysql> select *from DemoTable;
输出
+--------------+ | StudentId | +--------------+ | John74747 | | 8494575Carol | | 985755645 | | Carol-9032 | | 101 | +--------------+ 5 rows in set (0.00 sec)
以下是仅返回数字行的查询 -
mysql> select *from DemoTable where StudentId REGEXP '^[0-9]+$';
输出
+-----------+ | StudentId | +-----------+ | 985755645 | | 101 | +-----------+ 2 rows in set (0.17 sec)
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP