NET_IP_TO_STRING

Updated at:

The NET_IP_TO_STRING function converts an IPv4 or IPv6 address from the BINARY format to the STRING format.

Syntax

STRING NET_IP_TO_STRING(BINARY <addr>)

Parameters

addr: Required. The IPv4 or IPv6 address to convert, specified as a BINARY value.

Return value

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

  • If addr is 4 bytes, the function returns the corresponding IPv4 address as a STRING value.

  • If addr is 16 bytes, the function returns the corresponding IPv6 address as a STRING value.

  • If addr is not a BINARY value that represents an IPv4 or IPv6 address, the function returns an error.

  • If addr is NULL, the function returns NULL.

Examples

-- Returns the IPv4 address 255.255.255.0
SELECT NET_IP_TO_STRING(NET_IP_NET_MASK(4, 24));

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

-- Returns NULL 
SELECT NET_IP_TO_STRING(NULL);

Related functions

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