mysql 字符串存储过程_MySQL存储过程和字符串操作

bd96500e110b49cbb3cd949968f18be7.png

Hello,

I need to write a stored procedure in MySQL that loops through all rows in a table (the column types are TEXT and VARCHAR) and replaces certain characters in the column values with another character. For example, a certain column contains the text "ababa" and I want to change it to "acaca".

I can''t quite figure out the part about replacing a character in a string with another and could use some help with this!

Thank you very much!

Sylvain

解决方案You need to sort out if you''re wanting to replace a char or a string. The letter ''b'' is different than the word "ababa", so you should be a little more clear there: are you wanting to replace ''b'' with ''c'' or "ababa" with "acaca"?

Regardless, you''re going to want to use the UPDATE and REPLACE commands.

UPDATE your_table SET your_field=(REPLACE(your_field,''old-text'',''new-text'')

old-text is (are) the character(s) you wish to replace, and new-text is (are) the character(s) you''ll replace them with.

Cheers,

-jc

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值