HEX_TO_IP
Description
HEX_TO_IP
is a row function that converts a hexadecimal-encoded TEXT
value to a text representation of an IP address.Syntax
HEX_TO_IP
(STRING
)Return Value
Returns a value of type
TEXT
representing either an IPv4 or IPv6 address. The type of IP address returned depends on the input string. An 8 character hexadecimal string returns an IPv4 address. A 32 character long hexadecimal string returns an IPv6 address.IPv6 addresses are represented in full length, without removing any leading zeros and without using the compressed
::
notation. For example, 2001:0db8:0000:0000:0000:ff00:0042:8329
rather than 2001:db8::ff00:42:8329
.Input strings that don't contain either 8 or 32 valid hexadecimal characters return
NULL
.Input Parameters
- string
- Required. A field or expression that returns a hexadecimal-encodedTEXTvalue. The hexadecimal string must be either 8 characters long (in which case it's converted to an IPv4 address) or 32 characters long (in which case it's converted to an IPv6 address).
Examples
Return a plain text IP address for each hexadecimal-encoded string value in the
byte_encoded_ips
column:HEX_TO_IP([byte_encoded_ips])
Convert an 8 character hexadecimal-encoded string to a plain text IPv4 address:
HEX_TO_IP(AB20FE01) returns
171.32.254.1
Convert a 32 character hexadecimal-encoded string to a plain text IPv6 address:
HEX_TO_IP(FE800000000000000202B3FFFE1E8329) returns
fe80:0000:0000:0000:0202:b3ff:fe1e:8329