mahesh
mahesh

Reputation: 23

Replacing characters with specified one

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

Answers (2)

Adnan M. TURKEN
Adnan M. TURKEN

Reputation: 1594

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

Upvotes: 0

dlamotte
dlamotte

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 fs with ms, yields mmmmmm. You need an intermediary replace.

Upvotes: 2

Related Questions