1

我正在使用 Oracle 11.g 程序。我发现这个例子REGEXP_REPLACE只有两个参数(输入和模式)。它有效,但不是最佳的。我正在尝试使用REGEXP_REPLACE以循环出现在文本base64 之后和文本“ />之前出现的特定文本字符串的可变数量, 我可以让它只出现一次,但我不能使其正确循环。

Declare p_html    clob;
        l_image_clob  clob;
        l_image_count number;
Begin
p_html := '<p>Some header text base64,one start here and then this is the end one" /></p><p>Some header text base64,two start here and then this is the end two" /></p>';
l_image_count := REGEXP_COUNT(p_html, 'base64', 1, 'i');
If l_image_count > 0 Then
  For i In 1..l_image_count Loop
    l_image_clob := REGEXP_REPLACE(p_html, '(.*base64,)|(" />.*)');
    dbms_output.put_line(l_image_clob);
    -- code to process each occurrence individually.
  End Loop;
End If;
End;

我希望看到的数据结果是:

one start here and this is the end one 
two start here and this is the end two

上面的示例返回:

two start here and this is the end two
two start here and this is the end two

我已经尝试了几个选项,REXEXP_REPLACE但我似乎无法让它与变量一起使用i

4

1 回答 1

0

如果您现在还没有弄清楚,这应该会有所帮助。基本上,正则表达式匹配一个字符串,该字符串由最多(非贪婪)的任何字符组成,包括字符串“base64 comma”,然后是记住的下一个不是双引号的字符串组,然后是双引号引用并返回该匹配项的记忆组部分,每次在原始字符串中出现字符串“base64”时返回一次:

with tbl(p_html) as
( select '<p>Some header text base64,one start here and then this is the end one" /></p><p>Some header text base64,two start here and then this is the end two" /></p>'
  from dual
)
select REGEXP_substr(p_html, '.*?base64,([^"]*)"', 1, level, NULL, 1) text
from tbl
connect by level <= REGEXP_COUNT(p_html, 'base64', 1, 'i');


TEXT                                                                            
--------------------------------------------------------------------------------
one start here and then this is the end one                                     
two start here and then this is the end two                                     

2 rows selected.

将其包装在游标中进行循环,或者将其加载到集合中进行处理,但是您需要。

于 2015-04-16T21:10:43.140 回答