mysql 在位置替换字符 [英] mysql replace character at position

查看:24
本文介绍了mysql 在位置替换字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在这样的存储过程中有一个变量:声明 str varchar(10);set str = 'ABCD';

If I have a variable in a stored procedure like this: declare str varchar(10); set str = 'ABCD';

如何更改字符串中任意位置的字符?例如:在程序中 x 是 3.我需要改变 str 所以它变成str = 'AB*D';

How do I change a character in the string at an arbitrary position? For example: in the procedure x is 3. I need to change str so it becomes str = 'AB*D';

这意味着,由于 x 等于 3,因此字符串中第 3 位的字符应更改为 '*'.

This means that, as x is equals to 3, in the string, the character at the position 3, should be changed to '*'.

推荐答案

您可以通过字符串操作来做到这一点:

You can do this with string manipulations:

select concat(left(str, 2), '*', substring(str, 4, 10))

或者,您可以使用 insert() 函数:

Or, you can use the insert() function:

select insert(str, 3, 1, '*')

这篇关于mysql 在位置替换字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆