Let us first create a table −
mysql> create table DemoTable -> ( -> EmailId varchar(30) -> ); Query OK, 0 rows affected (0.53 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('[email protected]'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('[email protected]'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values('[email protected]'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('[email protected]'); Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+---------------------+ | EmailId | +---------------------+ | [email protected] | | [email protected] | | [email protected] | | [email protected] | +---------------------+ 4 rows in set (0.00 sec)
Here is the query to replace a part of the string −
mysql> update DemoTable -> set EmailId=replace(EmailId,'[email protected]','[email protected]'); Query OK, 2 rows affected (0.16 sec) Rows matched: 4 Changed: 2 Warnings: 0
Let us check the table records once again −
mysql> select *from DemoTable;
This will produce the following output −
+-------------------+ | EmailId | +-------------------+ | [email protected] | | [email protected] | | [email protected] | | [email protected] | +-------------------+ 4 rows in set (0.00 sec)