2014-03-25 58 views
2

這是Fiddle如何更改此正則表達式以獲得所需的輸出?

所需的輸出

Buy flood insurance. Act now. 
Buy flood insurance. Call now. 
Buy flood insurance. No change. 

這裏是我的嘗試:

with data_row as (
    select 'or buy flood insurance. Act now.' as disclaimer from dual union all 
    select 'or Buy flood insurance. Call now.' as disclaimer from dual union all 
    select 'Buy flood insurance. No change.' as disclaimer from dual) 
    select case   
     when regexp_like(disclaimer,'^or (B|b)uy flood insurance.*') then 
       regexp_replace(disclaimer,'^or (B|b)uy flood insurance.*','Buy flood insurance.')  
     else disclaimer 
     end as revised 
from data_row 
+0

請在此處顯示您的代碼。 – Cfreak

+0

很高興。我無法發佈任何長度的內容。我會零零碎碎,耐心等待。 – zundarz

+0

我再次收到此消息:http://meta.stackexchange.com/questions/197468/where-can-i-get-more-information-about-my-submission-error – zundarz

回答

1

只要使用likelower()找什麼需要改變,如果需要用一個硬編碼的大寫覆蓋B

select 
    case 
    when lower(message) not like 'or b%' then message 
    else 'B' || substr(message, 5) 
    end message 
from disclaimer 

請參閱SQLFiddle