转自 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;
如果要取出汉字的话转变一下就可以了
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;
如果要取出汉字的话转变一下就可以了
本文介绍了 Oracle 数据库中 TRANSLATE 函数的使用方法,通过示例展示了如何利用该函数从字符串中提取数字或特定字符,适用于数据清理和格式化场景。
668

被折叠的 条评论
为什么被折叠?



