Character exchange in a position - sql

2

I want to replace the third character of a string in firebird, example: 00028 by 00128, 00029 by 00129 ... Could someone help me, I tried to see by replace, but I can not determine the position

    
asked by anonymous 29.05.2018 / 16:07

1 answer

4

Firebird has overlay function.

overlay ('00029' placing '1' from 3)

Website with documentation and more examples: overlay

Another example would be for oracle , where you can use a expressão regular .

SELECT regexp_replace('00029','(^.{2})(.{1})(.*)$','X') FROM dual;

In this case, I placed an " X " to mark where the new number should be inserted. The first {2} is the position of the exchange and the {1} is the number of letters to be replaced.

    
29.05.2018 / 16:29