Skip to content

TRANSLATE

TRANSLATE(char, search_string, replacement_string)

Section titled “TRANSLATE(char, search_string, replacement_string)”
  • char: This refers to the string value to be processed. The TRANSLATE Oracle function operates on this parameter by scanning it for occurrences of characters found in the search_string and replacing them with the corresponding characters in the replacement_string.
  • search_string: This is the string of characters that TRANSLATE will look for in the char parameter. Each character is independently searched, without recognizing any particular order within the string.
  • replacement_string: This string of characters is used by TRANSLATE for replacing characters in the char parameter that match the characters found in the search_string. The position of each character in the replacement_string corresponds to the position of the character to be replaced in the search_string.
SELECT TRANSLATE('123-456-7890','0123456789','ABCDEFGHIJ') AS result
FROM dual;
RESULT
----------
ABC-DEF-GHIJ

In this example, the TRANSLATE function replaces each numeric character in the input string ‘123-456-7890’ with the corresponding character from the set ‘ABCDEFGHIJ’. Therefore, the function translates ‘1’ to ‘A’, ‘2’ to ‘B’, ‘3’ to ‘C’, ‘4’ to ‘D’, ‘5’ to ‘E’, ‘6’ to ‘F’, ‘7’ to ‘G’, ‘8’ to ‘H’, ‘9’ to ‘I’, and ‘0’ to ‘J’. The ’-’ is untouched since it’s not included in either set. The resulting string is ‘ABC-DEF-GHIJ’.