Purpose
This function replaces the characters in char1 that match the characters in char2 with the corresponding characters in char3.
Syntax
TRANSLATE(char1,char2,char3)
Parameters
Parameter |
Description |
|---|---|
| char1 | A character expression or variable. |
| char2 | The set of characters in char1 that need to be replaced. |
| char3 | The set of characters used to replace char2. |
Note
- The data types of
char1,char2, andchar3can beCHAR,VARCHAR2,NCHAR,NVARCHAR2, orCLOB. - If the length of
char3is greater than that ofchar2, the extra characters inchar3are invalid. - If the length of
char3is less than that ofchar2, the extra characters inchar2are replaced with empty characters (deleted). - If the length of
char3is0,NULLis returned. - If
char2contains duplicate characters, the replacement is based on the first occurrence of each duplicate character. For example, ifchar2isaabandchar3is123, allacharacters inchar1are replaced with1, and allbcharacters inchar1are replaced with3.
Return type
The same data type as char1.
Examples
Replace the characters a and e in the string OceanBase with A and E, respectively.
obclient> SELECT TRANSLATE('OceanBase','ae','AE') "TRANSLATE" FROM DUAL;
+-----------+
| TRANSLATE |
+-----------+
| OcEAnBAsE |
+-----------+
1 row in set
