我正在使用Oracle 12cR1。我需要一个 REGEX 模式来完全匹配 Oracle 源代码中的给定表名(即)匹配不能在数字、字母或下划线符号之前或之后。
我创建了一个虚拟源代码并尝试了以下内容。它没有获取所有所需的记录。我错过了什么?是否有一个正则表达式模式?
测试代码:
with names as (
select 'mytabname' tabname from dual union all
select 'mytabname1' from dual union all
select 'mytabname_' from dual union all
select 'mytabnameX' from dual union all
select '1mytabname' from dual union all
select '_mytabname' from dual union all
select 'Xmytabname' from dual union all
select '1mytabname_' from dual union all
select '1mytabnameX' from dual union all
select '_mytabname1' from dual union all
select 'Xmytabname1' from dual union all
select '_mytabnameX' from dual union all
select 'Xmytabname_' from dual union all
select '_mytabname_' from dual union all
select 'XmytabnameX' from dual union all
select '1mytabname1' from dual union all
select ' mytabname_' from dual union all
select '_mytabname ' from dual union all
select ' mytabname ' from dual union all
select ' mytabnameX' from dual union all
select 'Xmytabname ' from dual union all
select ' mytabname1' from dual union all
select '1mytabname ' from dual union all
select '.mytabname ' from dual union all
select ' mytabname.' from dual union all
select '.mytabname.' from dual union all
select '*mytabname' from dual union all
select ' mytabname*' from dual union all
select '*mytabname*' from dual union all
select 'defmytabnameabc' from dual)
select 'start'||tabname||'end' from names
where regexp_like(tabname, '[^a-zA-Z0-9_](mytabname)[^a-zA-Z0-9_]');
输出:
start mytabname end
start.mytabname end
start mytabname.end
start.mytabname.end
start mytabname*end
start*mytabname*end
输出遗漏以下记录
startmytabnameend
start*mytabnameend