在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)热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志