IPV4_STRING_TO_NUM

SinceVersion dev

IPV4_STRING_TO_NUM

description

Syntax

BIGINT IPV4_STRING_TO_NUM(VARCHAR ipv4_string)

Takes a string containing an IPv4 address in the format A.B.C.D (dot-separated numbers in decimal form). Returns a BIGINT number representing the corresponding IPv4 address in big endian.

notice

will return an error if the input string is not a valid IPv4 address or NULL

example

  1. mysql> select ipv4_string_to_num('192.168.0.1');
  2. +-----------------------------------+
  3. | ipv4_string_to_num('192.168.0.1') |
  4. +-----------------------------------+
  5. | 3232235521 |
  6. +-----------------------------------+
  7. 1 row in set (0.01 sec)
  8. mysql> select ipv4_string_to_num('invalid');
  9. ERROR 1105 (HY000): errCode = 2, detailMessage = (172.17.0.2)[CANCELLED][INVALID_ARGUMENT][E33] Invalid IPv4 value
  10. mysql> select addr_src, ipv4_string_to_num(addr_src) from ipv4_string_test where addr_src is null;
  11. ERROR 1105 (HY000): errCode = 2, detailMessage = (172.17.0.2)[CANCELLED][E33] Null Input, you may consider convert it to a valid default IPv4 value like '0.0.0.0' first

keywords

IPV4_STRING_TO_NUM, IP