132***-6ren">
gpt4 book ai didi

mysql - MySQL 中有类似 substr_replace 的东西吗?

转载 作者:行者123 更新时间:2023-11-29 01:19:38 25 4
gpt4 key购买 nike

我有这样的列数据“132154646878”我想从指定位置替换每个的一部分像这样的东西:

substr_replace("132154646878","***",4)

Output => 132***646878

MySQL 中有什么函数吗?

最佳答案

看起来您正在寻找 MySQL 的 INSERT功能。

INSERT(str, pos, len, newstr)

Returns the string str, with the substring beginning at position pos and len characters long replaced by the string newstr. Returns the original string if pos is not within the length of the string. Replaces the rest of the string from position pos if len is not within the length of the rest of the string. Returns NULL if any argument is NULL.

来源https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_insert

查询

SELECT INSERT("132154646878", 4, LENGTH('***'), "***");

p.s 请记住,当您在 newstr 参数中使用像 utf8 这样的多字节字符集时,您需要使用 CHAR_LENGTH()而不是关闭 LENGTH()

结果

| INSERT("132154646878", 4, LENGTH('***'), "***") |
| ----------------------------------------------- |
| 132***646878 |

View on DB Fiddle

关于mysql - MySQL 中有类似 substr_replace 的东西吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52605993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com