如何在 MySQL 字符串中更改特定字符?
要更改 MySQL 字符串中的特定字符,你可以将 CONCAT() 与 SUBSTRING() 结合使用。
让我们先创建一个表 −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Value varchar(200) ); Query OK, 0 rows affected (0.60 sec)
使用 insert 命令向表中插入一些记录 −
mysql> insert into DemoTable(Value) values('98764');
Query OK, 1 row affected (0.17 sec)以下是使用 select 语句显示表中所有记录的查询 −
mysql> select *from DemoTable;
这会产生以下输出 −
+----+-------+ | Id | Value | +----+-------+ | 1 | 98764 | +----+-------+ 1 row in set (0.00 sec)
以下是更改 MySQL 字符串中特定字符的查询。我们在此设置 X,其中放置了 6 −
mysql> select concat(substring(Value,1,3),'X',substring(Value,5)) from DemoTable;
这会产生以下输出 −
+-----------------------------------------------------+ | concat(substring(Value,1,3),'X',substring(Value,5)) | +-----------------------------------------------------+ | 987X4 | +-----------------------------------------------------+ 1 row in set (0.00 sec)
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP