2015-07-21 84 views
-5

我想從如何從字符串中刪除特定的單詞?

字符串中刪除(蘋果香蕉)= '我買了蘋果,香蕉,橘子和芒果'

NewString = '我買了,Orange和芒果'

+4

你用REPLACE試過了嗎? –

+1

谷歌如何使用替換命令,這是你最好的選擇。此外,發佈你已經嘗試過,爲什麼它不工作 – Vbasic4now

+0

可能重複的[從字符串中刪除特定的單詞](http://stackoverflow.com/questions/21527273/remove-specific-word-from-string) –

回答

0

這個什麼?

select replace(
      replace('I bought Apple , Banana , Orange and Mango', 'Apple'), 
     'Banana') 
from dual; 

declare 
    my_string varchar2(50) := 'I bought Apple , Banana , Orange and Mango'; 
begin 
    my_string := replace(replace(my_string, 'Apple'), 'Banana'); 
end; 
0

使用REGEXP_REPLACE避免鏈接多個替換功能在一起。

SELECT REGEXP_REPLACE(my_string, 'Apple|Banana', '') FROM my_table

0
select regexp_replace(source_string, '(^|\W)(Apple|Banana)(\W|$)', '\1\3', 1, 0, 'i') as new_string 
    from (select 'I bought Apple , Banana , Orange and Mango' as source_string 
    from dual); 


NEW_STRING 
I bought , , Orange and Mango 

此代碼替換整個單詞 「蘋果」 或 「香蕉」 不區分大小寫。

0

我會嘗試這樣的事情

選擇替換(更換(「我買了蘋果,香蕉,橘子和芒果」,「蘋果」),「香蕉」) 從雙;

相關問題