2012-10-31 46 views
0

我在這裏遇到問題。 在我的數據庫,我值在像628932323mobile_phone列,但我想改變每其中使用62 to 0使用SQL腳本在varchar2數據類型中更改SQL值

old value : 628932323 
new value : 08932323 

有人可以幫我解決我的問題行。感謝

+0

您是否需要在每個數字中替換*起始* 62s,或者您是否需要在每個數字中替換*每個* 62s? –

+0

是的。喲是對的 –

+1

所以,第一次出現或每次出現? ) –

回答

1

如果您使用的是Oracle 10g或更高版本,可以使用REGEXP_REPLACE功能http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions130.htm

select regexp_replace(your_column, '62([:digit:]*)', '0\2') 
from your_table; 

還是比較傳統的方式,而不:

select case 
     when your_column like '62%' then '0' || substr(your_column, 3) 
     else 
     your_column 
     end 
from your_table; 

只是要小心前導空格或您的電話號碼字符串中的其他字符。