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
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 | +--------------------------+ | <a href="https://www.facebook.com" rel="nofollow noopener noreferrer" target="_blank">https://www.facebook.com</a> | | <a href="https://www.google.com" rel="nofollow noopener noreferrer" target="_blank">https://www.google.com</a> | | <a href="https://www.gmail.com" rel="nofollow noopener noreferrer" target="_blank">https://www.gmail.com</a> | +--------------------------+ 3 rows in set (0.00 sec)
Advertisements
