TRANSLATE ... USING

2023-10-31 11:17:12  Updated

Purpose

TRANSLATE ... USING() converts a string into a specified database character set or national character set.

Syntax

TRANSLATE(char USING{ CHAR_CS | NCHAR_CS })

Parameters

Parameter Description
char The string to be converted. It can be of the CHAR, VARCHAR2, NCHAR, NVARCHAR2, or CLOB data type.
CHAR_CS Specifies that the source string is to be converted into the database character set.
NCHAR_CS Specifies that the source string is to be converted into the national character set.

Return type

  • If you specify CHAR_CS, the return type is VARCHAR2.

  • If you specify NCHAR_CS, the return type is NVARCHAR2.

Examples

The following example converts the string OceanBase to the VARCHAR2 and NVARCHAR2 data types and returns the lengths of the strings in bytes.

obclient> SELECT LENGTHB(TRANSLATE('OceanBase' USING CHAR_CS)) "VARCHAR2",
                 LENGTHB(TRANSLATE('OceanBase' USING NCHAR_CS)) "NVARCHAR2"
          FROM DUAL;
+----------+-----------+
| VARCHAR2 | NVARCHAR2 |
+----------+-----------+
|        9 |        18 |
+----------+-----------+
1 row in set

Contact Us