我想用OF替換OF單詞的實例。我只希望這能夠用完整的單詞來工作。因此,不在L_OF,DOF,OFZ,DOFD,OF_L等上。Oracle上的regexp_replace完整的單詞
我的代碼工作如下,但最後一個字符串除外。
它返回:
("OF"*OF + 2)
...相反:
("OF"*"OF" + 2)
我怎樣才能得到它的上一個工作中呢?
with stg as
(
select '(ofof+ol)' str from dual union all
select '(oof+ol+of)' from dual union all
select '(*of + 2)' from dual union all
select '(of*of + 2)' from dual
)
select str,
regexp_replace(upper(str), '(\W|^)(OF)(\W|$)', '\1"OF"\3') as str2
from stg
問題是缺少posix正則表達式中的lookarounds。我想要得到你想要的東西,你必須把它放在一個plsql過程中,循環或嵌套regexp_replace,然後在另一個替換中刪除多餘的引號。 – RLOG