让我们首先创建一个表-
mysql> create table DemoTable -> ( -> EmailId varchar(30) -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('John123@example.com'); mysql> insert into DemoTable values('John123@gmail.com'); mysql> insert into DemoTable values('John123@yahoo.com'); mysql> insert into DemoTable values('John123@example.com');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+---------------------+ | EmailId | +---------------------+ | John123@example.com | | John123@gmail.com | | John123@yahoo.com | | John123@example.com | +---------------------+ 4 rows in set (0.00 sec)
这是替换字符串的一部分的查询-
mysql> update DemoTable -> set EmailId=replace(EmailId,'John123@example.com','John123@gmail.com'); Rows matched: 4 Changed: 2 Warnings: 0
让我们再次检查表记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-------------------+ | EmailId | +-------------------+ | John123@gmail.com | | John123@gmail.com | | John123@yahoo.com | | John123@gmail.com | +-------------------+ 4 rows in set (0.00 sec)