All Products
Search
Document Center

MaxCompute:NET_IP_TO_STRING

Last Updated:Mar 25, 2026

Converts an IPv4 or IPv6 address from BINARY to STRING format, returning a human-readable IP address string.

Syntax

STRING NET_IP_TO_STRING(BINARY <addr>)

Parameters

ParameterRequiredTypeDescription
addrYesBINARYThe IPv4 or IPv6 address to convert. Must be a valid 4-byte (IPv4) or 16-byte (IPv6) binary value.

Return value

Returns a STRING value representing the IP address. The following rules apply:

  • If addr is 4 bytes, the function returns the corresponding IPv4 address.

  • If addr is 16 bytes, the function returns the corresponding IPv6 address.

  • If addr is not a valid IPv4 or IPv6 binary value, the function returns an error.

  • If addr is NULL, the function returns NULL.

Examples

Example 1: Convert a binary value to an IPv4 address

The following example uses NET_IP_NET_MASK to generate a 4-byte binary value, then converts it to an IPv4 address string.

SELECT NET_IP_TO_STRING(NET_IP_NET_MASK(4, 24));
-- Returns: 255.255.255.0

Example 2: Convert a binary value to an IPv6 address

The following example converts a 16-byte hex-encoded binary value to an IPv6 address string.

SELECT NET_IP_TO_STRING(CAST(unhex('00000000000000000000FFFFC0000280') AS BINARY));
-- Returns: ::ffff:192.0.2.128

Example 3: Handle a NULL input

SELECT NET_IP_TO_STRING(NULL);
-- Returns: NULL

Related functions

NET_IP_TO_STRING is a network function. For more information about network functions, see Network functions.