- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 can I find and replace in MySQL in a column with file path?
For thus, use MySQL REPLACE(). Let us first create a table −
mysql> create table DemoTable ( FolderLocation text ); Query OK, 0 rows affected (0.80 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('C/ProgramFiles/AllMySQLProgram'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('C/ProgramFiles/JavaChatApplication'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('C/ProgramFiles/Main/Image.png'); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------------------------------------+ | FolderLocation | +------------------------------------+ | C/ProgramFiles/AllMySQLProgram | | C/ProgramFiles/JavaChatApplication | | C/ProgramFiles/Main/Image.png | +------------------------------------+ 3 rows in set (0.00 sec)
Following is the query to perform find and replace in MySQL −
mysql> update DemoTable set FolderLocation=replace(FolderLocation,'C/ProgramFiles','E/MyFolder/Details'); Query OK, 3 rows affected (0.14 sec) Rows matched: 3 Changed : 3 Warnings : 0
Let us check the table records once again −
mysql> select *from DemoTable;
This will produce the following output −
+----------------------------------------+ | FolderLocation | +----------------------------------------+ | E/MyFolder/Details/AllMySQLProgram | | E/MyFolder/Details/JavaChatApplication | | E/MyFolder/Details/Main/Image.png | +----------------------------------------+ 3 rows in set (0.00 sec)
Advertisements
To Continue Learning Please Login
Login with Google