IPV4_STRING_TO_NUM_OR_DEFAULT
SinceVersion dev
IPV4_STRING_TO_NUM_OR_DEFAULT
description
Syntax
BIGINT IPV4_STRING_TO_NUM_OR_DEFAULT(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 0 if the input parameter is invalid ipv4 value or NULL
example
mysql> select ipv4_string_to_num_or_default('192.168.0.1');
+----------------------------------------------+
| ipv4_string_to_num_or_default('192.168.0.1') |
+----------------------------------------------+
| 3232235521 |
+----------------------------------------------+
1 row in set (0.01 sec)
mysql> select str, ipv4_string_to_num_or_default(str) from ipv4_str;
+-----------------+------------------------------------+
|str | ipv4_string_to_num_or_default(str) |
+-----------------+------------------------------------+
| 0.0.0.0 | 0 |
| 127.0.0.1 | 2130706433 |
| 255.255.255.255 | 4294967295 |
| invalid | 0 |
+-----------------+------------------------------------+
4 rows in set (0.01 sec)
mysql> select addr_src, ipv4_string_to_num_or_default(addr_src) from ipv4_string_test where addr_src is null;
+----------+-----------------------------------------+
| addr_src | ipv4_string_to_num_or_default(addr_src) |
+----------+-----------------------------------------+
| NULL | 0 |
+----------+-----------------------------------------+
1 row in set (0.09 sec)
keywords
IPV4_STRING_TO_NUM_OR_DEFAULT, IP