Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Implement MySQL REGEXP to fetch records with . and numbers
Let us first create a table −
mysql> create table DemoTable -> ( -> Version varchar(20) -> ); Query OK, 0 rows affected (0.77 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('1.0.0');
Query OK, 1 row affected (0.21 sec)
mysql> insert into DemoTable values('2.s6.9');
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable values('1.5.0');
Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+---------+ | Version | +---------+ | 1.0.0 | | 2.s6.9 | | 1.5.0 | +---------+ 3 rows in set (0.00 sec)
Here is the query to implement MySQL REGEXP to fetch records with . and numbers −
mysql> select *from DemoTable -> where Version regexp '^[0-9]+\.[0-9]+(\.[0-9]+)*';
This will produce the following output −
+---------+ | Version | +---------+ | 1.0.0 | | 1.5.0 | +---------+ 2 rows in set (0.00 sec)
Advertisements
