REGEXPR_REPLACE 字符串

REGEXPR_REPLACE string

如何替换以下字符串中的 &

'extends the functionality & of the & REPLACE function & by'

分别为 onetwothree

最后的结果应该是:

extends the functionality one of the two REPLACE function three by

您可以执行嵌套的 REPLACE_REGEXPR 函数,并始终用不同的字符串替换第一个(下一个)剩余匹配项。

SELECT REPLACE_REGEXPR
       ('&' IN REPLACE_REGEXPR 
               ('&' IN REPLACE_REGEXPR
                      ('&' IN 'extends the functionality & of the & REPLACE function & by'
                        WITH 'one' OCCURRENCE 1) 
                 WITH 'two' OCCURRENCE 1)  
         WITH 'three' OCCURRENCE 1) "replace_regexpr" 
FROM DUMMY;

(有点晚了,但是)使用一个的版本 REPLACE_REGEXPR:

SELECT
    REPLACE_REGEXPR(
        '([^&]*)&([^&]*)&([^&]*)&([^&]*)'
        IN 'extends the functionality & of the & REPLACE function & by'
        WITH 'onetwothree') "replace_regexpr"
FROM DUMMY
;

输出:

replace_regexpr                                                    |
-------------------------------------------------------------------|
extends the functionality one of the two REPLACE function three by |