开发者

Replacing characters with specified one

开发者 https://www.devze.com 2022-12-28 06:02 出处:网络
I have a string as follows - MFMFMF now i want to change this string to FMFMFM how to do this , help needed pls

I have a string as follows - MFMFMF

now i want to change this string to FMFMFM how to do this , help needed pls

i had tried

select replace(replace('mfmfmf','M','F'),'F','M') this gives 开发者_StackOverflow社区me result - MMMMMM which i donot what i want the output to be FMFMFM Need your help

D.Mahesh


Try:

select replace(replace(replace('mfmfmf', 'm', 'x'), 'f', 'm'), 'x', 'f') ...

It's because your first replace yields:

ffffff

And then replacing fs with ms, yields mmmmmm. You need an intermediary replace.


select replace(replace(replace('mfmfmf','M','X'),'F','M'),'X','F')

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号