All Products
Search
Document Center

MaxCompute:FROM_CHARSET

Last Updated:Mar 26, 2026

Decodes binary data from a specified source encoding into a UTF-8 string. If any input parameter is null, null is returned.

Syntax

STRING FROM_CHARSET(binary <source>, string <source_charset>[, string <mode>])

Parameters

source

Required. Type: BINARY. The binary data to decode.

source_charset

Required. Type: STRING. The source encoding of the binary data. Valid values: UTF-8, UTF-16, UTF-16LE, UTF-16BE, ISO-8859-1, US-ASCII, GB2312, GBK, GB18030.

mode

Optional. Type: STRING. The behavior when a character cannot be converted. If not specified, the function reports an error and stops execution. Valid values:

ValueDescription
NONEReports an error and stops execution. Default value.
TRANSLITReplaces the unconvertible character with a visually similar character.
IGNORESkips the unconvertible character and continues execution.

Return value

Returns a STRING value in UTF-8 encoding.

Input conditionReturn value
Any parameter is nullNULL
Any parameter is an empty stringError

Examples

Example 1: Decode UTF-8 encoded binary data with TRANSLIT mode

SELECT FROM_CHARSET(unhex('e58aa0e6b2b9e9949fe696a4e68bb70a'), 'UTF-8', 'TRANSLIT');

Result:

+------------+
| _c0        |
+------------+
| 加油锟斤拷
     |
+------------+

Example 2: Decode GBK-encoded binary data

SELECT FROM_CHARSET(unhex('b9feb9febac3a4ce'), 'GBK');

Result:

+------------+
| _c0        |
+------------+
| 哈哈好の       |
+------------+

Example 3: Null input returns null

SELECT FROM_CHARSET(unhex('b9feb9febac3a4ce'), null);

Result:

+------------+
| _c0        |
+------------+
| NULL       |
+------------+
Note

The UNHEX function returns a string that is represented by a hexadecimal string. For details, see UNHEX.

What's next

References