TRANSLATE

2024-12-02 03:48:26  Updated

Purpose

TRANSLATE() replaces characters in char1 that match char2 with the corresponding characters in char3.

Syntax

TRANSLATE(char1,char2,char3)

Parameters

Parameter Description
char1 The source character expression or variable.
char2 The set of characters to be replaced in char1.
char3 The set of characters to replace char2.

Note

  • char1, char2, and char3 each can be of the CHAR, VARCHAR2, NCHAR, NVARCHAR2, or CLOB data type.
  • If char3 contains more characters than char2, the extra characters at the end of char3 are invalid.
  • If char3 contains fewer characters than char2, the extra characters at the end of char2 are removed from the return value.
  • If char3 contains 0 characters, the function returns NULL.
  • If char2 contains duplicate characters, the mapping in char3 corresponding to the first occurrence of the character is used for replacement. For example, if char2 is aab and char3 is 123, the function replaces all a in char1 with 1 and all b with 3.

Return type

The return type is the same as the data type of char1.

Examples

The following example replaces a and e in the string OceanBase with A and E.

obclient> SELECT TRANSLATE('OceanBase','ae','AE') "TRANSLATE" FROM DUAL;
+-----------+
| TRANSLATE |
+-----------+
| OcEAnBAsE |
+-----------+
1 row in set

Contact Us