我想使用 regexp_substr 提取包名称。
例如:
create or replace package body something.pkg_test is
我想要那个:
pkg_test
我尝试使用lookbehind只是为了忽略“创建或替换包体某些内容。”:
select regexp_substr('create or replace package body something.pkg_test is','((?<!create\sor\sreplace\spackage\sbody\ssomething\.).)*$',1,1) from dual;
但是这不起作用。所以我只需要提取“创建或替换包体某事”和第一个空格或\n之间的包名称。
我需要它,因为我需要在编译 .sql 文件并将其插入表之前获得包名称。
最佳答案
我的猜测是,也许您正在尝试编写一些具有积极后视功能的表达式:
(?<=create\sor\sreplace\spackage\sbody\ssomething\.)\S*
或者,我们可以使用一些不带环视的表达式,例如:
create\sor\sreplace\spackage\sbody\ssomething\.(\S*).*
使用捕获组1
,我们的代码可能如下所示:
select regexp_replace('create or replace package body something.pkg_test is', 'create\sor\sreplace\spackage\sbody\ssomething\.(\S*).*', '\1') from dual;
但不确定。
Demo 2
演示
该表达式在 regex101.com 的右上角面板中进行了解释,如果您想探索/简化/修改它,请在this link中,如果您愿意,您可以观察它如何与一些示例输入匹配。
引用
关于sql - 如何使用 regexp_substr 提取包名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57366048/