
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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)
- Related Articles
- MySQL query to replace part of string before dot
- Replace part of a string with another string in C++
- Update a column value, replacing part of a string in MySQL?
- Sort a MySQL table column value by part of its value?
- How to replace a part of the string (domain name after @) using MySQL?
- Find and replace a part of URL records in MySQL?
- MySQL replace values in a table?
- How can we replace specific part of String and StringBuffer in Java?
- MySQL find/ replace string in fields?
- Update a column of text with MySQL REPLACE()
- MySQL query to replace a string after the last / in a column with directory links?
- MySQL query to replace a column value
- MySQL query to replace backslash from a varchar column with preceding backslash string values
- Does JavaScript have a method to replace part of a string without creating a new string?
- How to replace a character in a MySQL table?

Advertisements