All Products
Search
Document Center

MaxCompute:SAFE_CONVERT_BYTES_TO_STRING

Last Updated:Sep 17, 2026

Converts binary data to a string.

Syntax

STRING SAFE_CONVERT_BYTES_TO_STRING(BINARY <value>)

Parameters

value: Required. The BINARY value that you want to convert.

Return value

Returns a value of the STRING type. The following rules apply:

  • If the input is a STRING, the original string is returned.

  • An error is returned if the input parameter is NULL.

  • If the input contains an invalid UTF-8 character, NULL is returned.

Examples

-- Returns alibaba
SELECT SAFE_CONVERT_BYTES_TO_STRING(CAST ('alibaba' AS BINARY));

-- Returns abc
SELECT SAFE_CONVERT_BYTES_TO_STRING(X'616263');

-- Returns abc
SELECT SAFE_CONVERT_BYTES_TO_STRING(UNHEX('616263'));

-- Returns 010101
SELECT SAFE_CONVERT_BYTES_TO_STRING('010101');

-- An error is returned. FAILED: ODPS-0130071:[1,8] Semantic analysis exception - function SAFE_CONVERT_BYTES_TO_STRING is ambiguous with (VOID), candidates are STRING SAFE_CONVERT_BYTES_TO_STRING(BINARY arg0); STRING SAFE_CONVERT_BYTES_TO_STRING(STRING arg0)
SELECT SAFE_CONVERT_BYTES_TO_STRING(null);

-- The input parameter contains an invalid UTF-8 character. NULL is returned.
SELECT SAFE_CONVERT_BYTES_TO_STRING(UNHEX('\xc2'));

Related functions

SAFE_CONVERT_BYTES_TO_STRING is a string function. For more information about functions that search for strings or convert string formats, see String Functions Overview.