日期:2014-05-16  浏览次数:20364 次

translate去掉字母等字符,保留数字
转自 http://www.cnblogs.com/gkl0818/archive/2009/03/01/1400990.html

ORACLE中translate的妙用
  下面是文档中的话



The following statement translates a license number. All letters 'ABC...Z' are translated to 'X' and all digits '012 . . . 9' are translated to '9':

SELECT TRANSLATE('2KRW229',
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'9999999999XXXXXXXXXXXXXXXXXXXXXXXXXX') "License"
FROM DUAL;
License
--------
9XXX999



The following statement returns a license number with the characters removed and the digits remaining:

SELECT TRANSLATE('2KRW229',
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', '0123456789')
"Translate example"
FROM DUAL;
Translate example
-----------------
2229



我们在利用TRANSLATE取出一个字段中的数字或文字的时候就可以巧用这个函数



select translate('23456中国3-00=.,45','0123456789'||'23456中国3-00=.,45','0123456789') from dual;



如果要取出汉字的话转变一下就可以了