MySQL 查询从列值中替换特殊字符
mysqlmysqli database更新于 2024/8/10 8:44:17
首先我们创建一个表 −
mysql> create table DemoTable1574 -> ( -> StudentCode varchar(20) -> ); Query OK, 0 rows affected (0.59 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable1574 values('111_Carol');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable1574 values('______');
Query OK, 1 row affected (0.30 sec)
mysql> insert into DemoTable1574 values('David_12345');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable1574 values('______');
Query OK, 1 row affected (0.12 sec)
使用 select 语句显示表中的所有记录 −
mysql> select * from DemoTable1574;
这将产生以下输出 −
+-------------+ | StudentCode | +-------------+ | 111_Carol | | ______ | | David_12345 | | ______ | +-------------+ 4 rows in set (0.00 sec)
这是要替换的查询 −
mysql> update DemoTable1574 set StudentCode=replace(StudentCode,'______','Mike_007'); Query OK, 2 rows affected (0.38 sec) Rows matched: 4 Changed: 2 Warnings: 0
让我们再次检查表记录 −
mysql> select * from DemoTable1574;
这将产生以下输出 −
+-------------+ | StudentCode | +-------------+ | 111_Carol | | Mike_007 | | David_12345 | | Mike_007 | +-------------+ 4 rows in set (0.00 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

