您可能想找到一个与正则表达式单词边界和regexp_replace
一起使用的解决方案: ^|
|$
with ct as (
select '123 RD' add1, 'APT 2' add2, 'BLDG 1' add3 from dual union all
select '123 3RD street' add1, 'APT 2' add2, 'BLDG 1' add3 from dual union all
select 'test DR' add1, '' add2, '' add3 from dual union all
select 'main RD' add1, '' add2, 'BLDG2' add3 from dual
),
lk as (
select 'RD' abbreviation, 'road' completestreet from dual union all
select 'APT' abbreviation, 'apartment' completestreet from dual union all
select 'BLDG' abbreviation, 'building' completestreet from dual union all
select 'DR' abbreviation, 'drive' completestreet from dual
),
recursion (add1, add2, add3, l) as (
select add1, add2, add3, 1 l from ct union all
select regexp_replace(add1, '(^| )' ||abbreviation || '( |$)', '\1' || completestreet || '\2'),
regexp_replace(add2, '(^| )' ||abbreviation || '( |$)', '\1' || completestreet || '\2'),
regexp_replace(add3, '(^| )' ||abbreviation || '( |$)', '\1' || completestreet || '\2'),
l+1
from recursion join (
select
row_number() over (order by abbreviation) r,
abbreviation,
completestreet
from lk
) lk
on l=r
)
select substrb(add1, 1, 30),
substrb(add2, 1, 30),
substrb(add3, 1, 30)
from recursion
where l=(select count(*)+1 from lk);