Reputation: 23
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 me result - MMMMMM which i donot what i want the output to be FMFMFM Need your help
D.Mahesh
Upvotes: 2
Views: 191
Reputation: 1594
select replace(replace(replace('mfmfmf','M','X'),'F','M'),'X','F')
Upvotes: 0
Reputation: 6385
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.
Upvotes: 2