oracle函数之:translate


今天在阅读一份document的时候发现了一个函数:translate
先看看语法及其介绍吧。

TRANSLATE(char, from, to)
Returns Char with all occurrences of each character in From replaced by its corresponding characte r in To.
Characters in Char that are not in From are not replaced.


示例
SQL> select translate('asdfasdfaaa','a','#') from dual;
TRANSLATE('ASDFASDFAAA','A','#
------------------------------
#sdf#sdf###
SQL> select translate('asdfasdfaaa','ad','#') from dual;
TRANSLATE('ASDFASDFAAA','AD','
------------------------------
#sf#sf###
SQL> select translate('asdfasdfaaa','da','#') from dual;
TRANSLATE('ASDFASDFAAA','DA','
------------------------------
s#fs#f
SQL>

有点看不太明白,在一开始的时候,特别是第2、3个,摸了1、2分钟才搞明白。其实也挺简单的,就是replace的超集罢了,注意第2、3个参数就好了,重点就在这。

你可能感兴趣的:(translate)