 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to escape parentheses in MySQL REGEXP clause and display only specific values with parentheses?
Let us first create a table −
mysql> create table DemoTable1908 ( Code text ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1908 values('MySQL(1)Database'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1908 values('MongoDB 2 Database'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1908 values('MySQL(3)Database'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1908 values('SQL Server(10)Database'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1908 values('MySQL 8 Database'); Query OK, 1 row affected (0.00 sec) Display all records from the table using select statement −
mysql> select * from DemoTable1908;
This will produce the following output −
+------------------------+ | Code | +------------------------+ | MySQL(1)Database | | MongoDB 2 Database | | MySQL(3)Database | | SQL Server(10)Database | | MySQL 8 Database | +------------------------+ 5 rows in set (0.00 sec)
Here is the query to escape parentheses in a REGEXP clause and display only the paratheses value with () −
mysql> select * from DemoTable1908 where Code regexp '^MySQL[(][0-9][)]Database';
This will produce the following output −
+------------------+ | Code | +------------------+ | MySQL(1)Database | | MySQL(3)Database | +------------------+ 2 rows in set (0.00 sec)
Advertisements
 