stored procedures - mysql replace character at position
Get the solution ↓↓↓If I have a variable in a stored procedure like this: declare str varchar(10); set str = 'ABCD';
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';
This means that, as x is equals to 3, in the string, the character at the position 3, should be changed to '*'.
Answer
Solution:
You can do this with string manipulations:
select concat(left(str, 2), '*', substring(str, 4, 10))
Or, you can use theinsert()
function:
select insert(str, 3, 1, '*')
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: warning: undefined array key
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.