鑑於模式你介紹一下,你可以使用正則表達式去除你不想要的部分。您似乎有由^|^
分隔的元素,因此您可以刪除由the regexp_replace()
function和(\^\|\^.*\^\|\^)
(轉義特殊字符)組成的模式所包含的任何內容,但您也希望在第一個分隔符之前刪除文本;你也許可以簡化此一點,但作爲一個起點和一個CTE來提供你的兩個樣本值:
with t as (
select '2015 Test Plan^|^^|^g9xg3^|^read^|^^|^2015 Test Plan - HR Approval has been accepted^|^This is another test. I will accept!<html><a href="https://URL_REMOVED_> Click here to view the details' as text from dual
union all select 'TemplateName^|^^|^USERID^|^read/unread^|^^|^Accepted or Inquired^|^THE TEXT I WANT TO KEEP <html>web url' as text from dual
)
select regexp_replace(text, '^.*(\^\|\^.*\^\|\^)')
from t;
KEEP
--------------------------------------------------------------------------------------------------------
This is another test. I will accept!<html><a href="https://URL_REMOVED_> Click here to view the details
THE TEXT I WANT TO KEEP <html>web url
然後,它的結果可以被送入第二regexp_replace
,消除任何開始<html>
:
with t as (
select '2015 Test Plan^|^^|^g9xg3^|^read^|^^|^2015 Test Plan - HR Approval has been accepted^|^This is another test. I will accept!<html><a href="https://URL_REMOVED_> Click here to view the details' as text from dual
union all select 'TemplateName^|^^|^USERID^|^read/unread^|^^|^Accepted or Inquired^|^THE TEXT I WANT TO KEEP <html>web url' as text from dual
)
select regexp_replace(regexp_replace(text, '^.*(\^\|\^.*\^\|\^)'), '<html.*') as keep
from t;
KEEP
----------------------------------------
This is another test. I will accept!
THE TEXT I WANT TO KEEP
Read more about Oracle's regular expression support。
您只顯示要刪除的固定字符串。您是否有某種模式/規則來識別要保留的部件以及要移除的部件? – 2015-02-17 23:20:12
對不起,延遲的答覆,並感謝您的答覆。不幸的是,字符串會有所不同。他們將遵循「TEMPLATENAME^| ^^ |^USERID^|^READ/UNREAD^|^^ | ^接受/查詢^ | ^」我想要保留 web url「的文本的一般模式 - 換句話說,TEMPLATENAME將改變,USERID將改變,READ/UNREAD將波動,ACCEPTED/INQUIRED將隨着其他狀態的變化而波動。唯一的靜態結果看起來是url鏈接,從標籤開始並以「點擊這裏查看細節」。 – jdgaub 2015-02-18 15:03:54