All Products
Search
Document Center

MaxCompute:NET_IP_FROM_STRING

Last Updated:Mar 26, 2026

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

Syntax

BINARY NET_IP_FROM_STRING(STRING <str>)

Parameters

str: Required. A STRING value representing an IPv4 or IPv6 address. Supported formats:

  • IPv4: Dot-decimal notation, for example, 10.1.x.x.

  • IPv6: Colon-separated format, for example, 1234:5678:90ab:cdef:1234:5678:90ab:cdef. See IP Version 6 Addressing Architecture for the full specification.

CIDR notation is not supported. For example, 10.1.x.x/xx is invalid input.

Return value

Returns a BINARY value:

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

  • If the input is an invalid IP address, an error is reported.

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

Examples

The following examples cover IPv4, IPv6, and edge-case inputs.

-- IPv4: returns 0123
SELECT NET_IP_FROM_STRING('48.49.50.51');

-- IPv6 loopback: returns =00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=01
SELECT NET_IP_FROM_STRING('::1');

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

-- IPv4-mapped IPv6: 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');

-- NULL input: returns NULL
SELECT NET_IP_FROM_STRING(NULL);

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

Related functions

NET_IP_FROM_STRING is a network function. For the full list of network functions, see Network functions.