TRANSLATE()

All functions > STRING > TRANSLATE()

Returns a string with character-level replacements applied based on character-to-character mappings.

Signatures

Returns: String with character-level replacements applied

TRANSLATE(string: VARCHAR, from_chars: VARCHAR, to_chars: VARCHAR) → VARCHAR
sql
ParameterTypeRequiredDescription
stringVARCHARYesString to transform
from_charsVARCHARYesCharacters to replace
to_charsVARCHARYesCharacters to replace with (parallel mapping to from_chars)

Notes

  • Character-by-character replacement (not whole substrings)
  • Each character in from_chars maps to the character at the same index in to_chars
  • If to_chars is shorter than from_chars, the extra source characters are removed from the result
  • If any argument is NULL the result is NULL (use NULL(VARCHAR); bare NULL fails inference)

Examples

FeatureQL
SELECT
    f1 := TRANSLATE('12345', '123', 'ABC'), -- Replace digits with letters
    f2 := TRANSLATE('Hello World', 'ol', 'OL'), -- Case change for specific chars
    f3 := TRANSLATE('AABBCC', 'ABC', 'XYZ'), -- Multiple replacements
    f4 := TRANSLATE('123-45-6789', '-', '.'), -- Replace dashes with dots
    f5 := TRANSLATE('test', 'abcd', 'ABCD'), -- No matching characters
    f6 := TRANSLATE(NULL(VARCHAR), 'a', 'b') -- NULL yields NULL
;
Result
f1 VARCHARf2 VARCHARf3 VARCHARf4 VARCHARf5 VARCHARf6 VARCHAR
ABC45HeLLO WOrLdXXYYZZ123.45.6789testNULL

Last update at: 2026/05/26 17:22:09