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 f
s with m
s, yields mmmmmm
. You need an intermediary replace.
select replace(replace(replace('mfmfmf','M','X'),'F','M'),'X','F')
精彩评论