Multiple REPLACE function in Oracle

后端 未结 6 1778
陌清茗
陌清茗 2020-12-05 07:25

I am using the REPLACE function in oracle to replace values in my string like;

 SELECT REPLACE(\'THE NEW VALUE IS #VAL1#\',\'#VAL1#\',\'55\') fr         


        
6条回答
  •  有刺的猬
    2020-12-05 07:43

    Bear in mind the consequences

    SELECT REPLACE(REPLACE('TEST123','123','456'),'45','89') FROM DUAL;
    

    will replace the 123 with 456, then find that it can replace the 45 with 89. For a function that had an equivalent result, it would have to duplicate the precedence (ie replacing the strings in the same order).

    Similarly, taking a string 'ABCDEF', and instructing it to replace 'ABC' with '123' and 'CDE' with 'xyz' would still have to account for a precedence to determine whether it went to '123EF' or ABxyzF'.

    In short, it would be difficult to come up with anything generic that would be simpler than a nested REPLACE (though something that was more of a sprintf style function would be a useful addition).

提交回复
热议问题