Wednesday, March 21, 2012

Replace character from string

Hi,

How to replace specific character from a string.
I have '100001'
i want to replace 2nd chracter '0' with '1' .i.e.
Result output would be

'110001'

Can we do it by using oracle function i.e Replace and transalate

Thanks
PaginitYou could change this specific string using REPLACE:

REPLACE('100001','10','11')

But in general, that would not work - e.g. it would not work for the string '100010', because it would change the 2nd and 6th characters both to 1.

To specificy a particular character position for change you must use SUBSTR:

SUBSTR(string,1,1) || '1' || SUBSTR(string, 3)

This takes the first character, appends a '1', and then appends the rest of the string from position 3 (omitting position 2).sql

No comments:

Post a Comment