Replacing characters with the specified

I have a line like this: MFMFMF

now i want to change this line to FMFMFM, how to do it, help you need pls

I tried

select replace (replace ('mfmfmf', 'M', 'F'), 'F', 'M'). this gives me the result - MMMMMM which i dont know i want the output to be FMFMFM Your help is needed.

D.Mahesh

+2


a source to share


2 answers


Try:

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

      

This is because your first replacement gives:



ffffff

      

And then replacing it f

with m

s, we get mmmmmm

. You need an intermediate replacement.

+3


a source


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



+1


a source







All Articles