更换记录最简单的方法是使用MySQL REPLACE()
-
mysql> create table DemoTable2025 -> ( -> URL text -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable2025 values('http=//www.facebook.com'); mysql> insert into DemoTable2025 values('http=//www.google.com'); mysql> insert into DemoTable2025 values('http=//www.gmail.com');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable2025;
这将产生以下输出-
+-------------------------+ | URL | +-------------------------+ | http=//www.facebook.com | | http=//www.google.com | | http=//www.gmail.com | +-------------------------+ 3 rows in set (0.00 sec)
这是查找和替换一部分URL记录的查询-
mysql> update DemoTable2025 -> set URL=replace(URL,'http=','https:'); Rows matched: 3 Changed: 3 Warnings: 0
让我们再次检查表记录-
mysql> select *from DemoTable2025;
这将产生以下输出-
+--------------------------+ | URL | +--------------------------+ | https://www.facebook.com | | https://www.google.com | | https://www.gmail.com | +--------------------------+ 3 rows in set (0.00 sec)