pl sql dbms_lob.substr 或 regex_substr 在新行之间获取文本

Mar*_*iah -1 oracle plsql

我得到了一个带有包含下一个字符串的 clob 字段的表:

"hello world Chr(13)
hello world 2 chr(13)
hello world 3"
Run Code Online (Sandbox Code Playgroud)

我试图hello world 2在第一个和最后一个断行之间获取文本“ ”,但我仍然不能。

我尝试成功DBMS_LOB.INSTRregexp_substr失败......有人可以在这里帮助我吗?

非常感谢。

mat*_*guy 5

假设您的字符串实际上是我在评论中建议的(并反映在下面的测试字符串中):

with inputs ( str ) as (
       select to_clob('hello world' || chr(13) || 'hello world 2' || chr(13) ||
                                                           'hello world 3') from dual
     )
select dbms_lob.substr(str, 
                dbms_lob.instr(str, chr(13), 1, 2) - dbms_lob.instr(str, chr(13), 1, 1), 
                dbms_lob.instr(str, chr(13), 1, 1))           as second_line
from   inputs;



SECOND_LINE                                                                     
----------------
hello world 2 
Run Code Online (Sandbox Code Playgroud)

每当您必须处理 CLOB 时,请使用 dbms_lob 函数;它们比正则表达式解决方案快得多。