
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
Find and Replace a Part of URL Records in MySQL
The simplest way to replace records is using MySQL REPLACE() −
mysql> create table DemoTable2025 -> ( -> URL text -> ); Query OK, 0 rows affected (0.88 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable2025 values('http=//www.facebook.com'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable2025 values('http=//www.google.com'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable2025 values('http=//www.gmail.com'); Query OK, 1 row affected (0.26 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable2025;
This will produce the following output −
+-------------------------+ | URL | +-------------------------+ | http=//www.facebook.com | | http=//www.google.com | | http=//www.gmail.com | +-------------------------+ 3 rows in set (0.00 sec)
Here is the query to find and replace a part of URL records −
mysql> update DemoTable2025 -> set URL=replace(URL,'http=','https:'); Query OK, 3 rows affected (0.21 sec) Rows matched: 3 Changed: 3 Warnings: 0
Let us check the table records once again −
mysql> select *from DemoTable2025;
This will produce the following output −
+--------------------------+ | URL | +--------------------------+ | https://www.facebook.com | | https://www.google.com | | https://www.gmail.com | +--------------------------+ 3 rows in set (0.00 sec)
Advertisements