All Products
Search
Document Center

MaxCompute:NET_IP_FROM_STRING

Last Updated:Oct 21, 2025

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

Syntax

BINARY NET_IP_FROM_STRING (STRING <str>)

Parameters

str: Required. A value of the STRING type that represents the IPv4 or IPv6 address to be converted. The supported formats are as follows:

  • IPv4: The dot-decimal notation. For example, 10.1.x.x.

  • IPv6: The colon-separated format. For example, 1234:5678:90ab:cdef:1234:5678:90ab:cdef. For more information, see IP Version 6 Addressing Architecture.

Note

This function does not support CIDR notation, such as 10.1.x.x/xx.

Return value

This function returns an IP address of the BINARY type. The following rules apply:

  • If the input parameter is NULL, the function returns NULL.

  • If the input parameter is invalid, an error is reported.

    Note

    If the odps.sql.udf.strict.mode parameter is set to false, the system returns NULL instead of throwing an exception for an invalid input parameter.

Examples

--Returns 0123  
SELECT NET_IP_FROM_STRING('48.49.50.51');

--Returns =00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=01
SELECT NET_IP_FROM_STRING('::1');

--Returns 0123456789@ABCDE
SELECT NET_IP_FROM_STRING('3031:3233:3435:3637:3839:4041:4243:4445');

--Returns =00=00=00=00=00=00=00=00=00=00=FF=FF=C0=00=02=80
SELECT NET_IP_FROM_STRING('::ffff:192.0.2.128');

--Returns NULL
SELECT NET_IP_FROM_STRING(NULL);

-- An error is returned. FAILED: ODPS-0130071:[0,0] Semantic analysis exception - physical plan generation failed: ODPS-0121095:Invalid argument - Invalid IP address: ::wxyz
SELECT NET_IP_FROM_STRING('::wxyz');

Related functions

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