Replace function problem

In one of my results, I came across char data. I want to create another column that carries over the changed data from the first column. There I want to exchange all "ö" for oe.

I tried like this:

Select NAME1,
    case when POSSTR(NAME1, 'ö') is not null then REPLACE(NAME1, 'ö', 'oe')
    end As __NAME1
from xyz;

      

and it did not pass. I don't get the error, but ö is not being replaced.

Am I making a mistake or is it just not possible to perform this operation?

Thanks! Patrick

0


a source to share


2 answers


As per the DB2 documentation, POSSTR returns 0 (not NULL) if no row is found.



+1


a source


You want your second column to display all rows, both modified and unchanged, which you can simply use:

Select 
    NAME1,
    REPLACE(NAME1, 'ö', 'oe') As __NAME1
from xyz;

      



also you can check this:

Select 
    NAME1,
    REPLACE(NAME1, 'ö', 'oe') As __NAME1
from 
    xyz
where
    POSSTR(NAME1, 'ö') <> 0

      

+1


a source







All Articles