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
| Parameter | Type | Required | Description |
|---|---|---|---|
string | VARCHAR | Yes | String to transform |
from_chars | VARCHAR | Yes | Characters to replace |
to_chars | VARCHAR | Yes | Characters to replace with (parallel mapping to from_chars) |
Notes
- Character-by-character replacement (not whole substrings)
- Each character in
from_charsmaps to the character at the same index into_chars - If
to_charsis shorter thanfrom_chars, the extra source characters are removed from the result - If any argument is NULL the result is NULL (use
NULL(VARCHAR); bareNULLfails 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 VARCHAR | f2 VARCHAR | f3 VARCHAR | f4 VARCHAR | f5 VARCHAR | f6 VARCHAR |
|---|---|---|---|---|---|
| ABC45 | HeLLO WOrLd | XXYYZZ | 123.45.6789 | test | NULL |
On this page