- Trending Categories
- 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
Replace part of string in MySQL table column?
To replace part of string in MySQL table column, you can use REPLACE(). Following is the syntax −
update yourTableName set yourColumnName = REPLACE(yourColumnName ,'yourOldValue','yourNewValue');
Let us first create a table −
mysql> create table replacePartOfStringDemo -> ( -> WebsiteURL varchar(100) -> ); Query OK, 0 rows affected (0.47 sec)
Following is the query to insert records in the table using insert command −
mysql> insert into replacePartOfStringDemo(WebsiteURL) values('www.mysqlQuestion.com'); Query OK, 1 row affected (0.14 sec)
Following is the query to display all records from the table using select statement −
mysql> select * from replacePartOfStringDemo;
This will produce the following output −
+-----------------------+ | WebsiteURL | +-----------------------+ | www.mysqlQuestion.com | +-----------------------+ 1 row in set (0.00 sec)
Let us now replace part of a string in MySQL table column. Here, “mysqlQuestion“ is replaced with “mysql” −
mysql> update replacePartOfStringDemo set WebsiteURL=REPLACE(WebsiteURL,'www.mysqlQuestion.com','www.mysql.com'); Query OK, 1 row affected (0.20 sec) Rows matched: 1 Changed: 1 Warnings: 0
Let us check the table record once again −
mysql> select * from replacePartOfStringDemo;
This will produce the following output −
+---------------+ | WebsiteURL | +---------------+ | www.mysql.com | +---------------+ 1 row in set (0.00 sec)
Advertisements