如何从 MySQL 中的列中删除特定字符的所有实例?
mysqlmysqli database更新于 2025/5/25 22:36:17
首先我们创建一个表 −
mysql> create table DemoTable -> ( -> FirstName varchar(100) -> ); Query OK, 0 rows affected (0.41 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable values('Adam^^^');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable values('^^^^^^^^Carol');
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable values('Robert^^^^^^');
Query OK, 1 row affected (0.14 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable;
输出
这将产生以下输出 −
+---------------+ | FirstName | +---------------+ | Adam^^^ | | ^^^^^^^^Carol | | Robert^^^^^^ | +---------------+ 3 rows in set (0.00 sec)
以下查询用于从 MySQL 中的列中删除特定字符的所有实例。这里,我们删除所有特殊字符 ^ −
mysql> update DemoTable set FirstName=replace(FirstName,'^',''); Query OK, 3 rows affected (0.20 sec) Rows matched: 3 Changed: 3 Warnings: 0
让我们再次检查表记录 −
mysql> select *from DemoTable;
输出
这将产生以下输出 −
+-----------+ | FirstName | +-----------+ | Adam | | Carol | | Robert | +-----------+ 3 rows in set (0.00 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

