TRANSLATE is a character-by-character search-and-replace function. It scans an input string, looks for every occurrence of any character listed in the second argument, and substitutes it with the character that appears in the same position of the third argument. If the third argument is shorter than the second, characters with no counterpart are removed. TRANSLATE is executed in a single pass, making it faster than nesting multiple REPLACE calls. It is case-sensitive, works only on individual characters (not substrings), and returns NULL when any input is NULL.
source_string
(TEXT) - The string to be processed.search_chars
(TEXT) - Characters to find. Each character is treated independently.replace_chars
(TEXT) - Characters to substitute. Positionally matched to search_chars. If shorter, extra search characters are deleted.REPLACE, REGEXP_REPLACE, SUBSTRING, LEFT, RIGHT, CONVERT
SQL:1999 core specification; available in PostgreSQL 7.4 and Oracle 8i.
TRANSLATE works character-by-character, while REPLACE targets whole substrings. Use TRANSLATE when you need to swap or delete many single characters in one pass.
Characters in the search string that lack a positional counterpart are removed from the result.
Yes. 'A' and 'a' are treated as different characters unless you explicitly include both in the search list.
It can, provided your database and column encoding support them. Each Unicode code point counts as one character for translation.