在MySQL中是否有类似substr_replace的东西?

为此,请使用INSERT()MySQL中的函数。INSERT(str,pos,len,newstr)返回字符串str,子字符串从pos位置开始,并且len个字符由字符串newstr替换。如果pos不在字符串的长度内,则返回原始字符串。

如果len不在字符串其余部分的长度内,它将从位置pos替换字符串的其余部分。如果任何参数为NULL,则返回NULL。

让我们首先创建一个表-

mysql> create table DemoTable
(
   Password varchar(50)
);

使用插入命令在表中插入一些记录-

mysql> insert into DemoTable values('76367_____8793443');
mysql> insert into DemoTable values('12345_____9899984322');
mysql> insert into DemoTable values('99999_____4747747432');

使用select语句显示表中的所有记录-

mysql> select *from DemoTable;

这将产生以下输出-

+----------------------+
| Password             |
+----------------------+
| 76367_____8793443    |
| 12345_____9899984322 |
| 99999_____4747747432 |
+----------------------+
3 rows in set (0.00 sec)

以下是INSERT()在MySQL中为substr_replace实现功能的查询-

mysql> select insert(Password,5,length('PPPPPP'),'PPPPPP') from DemoTable;

这将产生以下输出-

+----------------------------------------------+
| insert(Password,5,length('PPPPPP'),'PPPPPP') |
+----------------------------------------------+
| 7636PPPPPP8793443                            |
| 1234PPPPPP9899984322                         |
| 9999PPPPPP4747747432                         |
+----------------------------------------------+
3 rows in set (0.00 sec)