pl/sql 中的 oracle regexp_instr 不工作

oracle regexp_instr in pl/sql doesn't work

我有一个 clob,里面有 pl/sql 代码。
最后得看看里面有没有exit命令

所以以下是不允许的:

Some code ...
exit

Some code ...
exit;

Some code ...
exit
/

但以下是允许的:

Some code ...
exit when ... Some code ...

Some code ...
Some other code ... -- If this happens than exit
Some code ...

我已尝试使用以下代码,但它不起作用:

if regexp_instr(v_clob, chr(10) || 'exit[;]?[^[[:blank:]]]', 1, 1, 0, 'i') != 0 then

你有两个方括号,你没有匹配行尾;这适用于您的示例:

regexp_instr(v_clob, chr(10) || 'exit(;)?([^[:blank:]]|$)', 1, 1, 0, 'i')

因为你想在一行的开头进行匹配,所以这样做会更简单(并且可能更安全地同时捕获 LF 和 CRLF/LFCR):

regexp_instr(v_clob, '^exit(;)?([^[:blank:]]|$)', 1, 1, 0, 'im')

db<>fiddle 在 CTE 中显示样本值和原始结果加上这两个选项的输出。