TRANSLATE 함수는 지정된 문자열 string 내에 문자열 from_substring에 지정된 문자가 존재한다면, 이를 to_substring에 지정된 문자로 대체한다. 이때, from_substring과 to_substring에 지정되는 문자의 순서에 따라 대응 관계를 가지며, to_substring과 1:1 대응되지 않는 나머지 from_substring 문자는 문자열 string 내에서 모두 제거된다. REPLACE 함수와 유사하게 동작하나, TRANSLATE 함수에서는 to_substring 인자를 생략할 수 없다.
TRANSLATE( string, from_substring, to_substring )
string :
• character string
• NULL
from_substring :
• character string
• NULL
to_substring :
• character string
• NULL
--it returns NULL when an argument is specified with NULL value
SELECT TRANSLATE('12345abcdeabcde','abcde', NULL);
======================
NULL
--it translates 'a','b','c','d','e' into '1', '2', '3', '4', '5' respectively
SELECT TRANSLATE('12345abcdeabcde', 'abcde', '12345');
======================
'123451234512345'
--it translates 'a','b','c' into '1', '2', '3' respectively and removes 'd's and 'e's
SELECT TRANSLATE('12345abcdeabcde','abcde', '123');
======================
'12345123123'
--it removes 'a's,'b's,'c's,'d's, and 'e's in the string
SELECT TRANSLATE('12345abcdeabcde','abcde', '');
======================
'12345'
--it only translates 'a','b','c' into '3', '4', '5' respectively
SELECT TRANSLATE('12345abcdeabcde','ABabc', '12345');
======================
'12345345de345de'