IPV4_STRING_TO_NUM_OR_NULL
IPV4_STRING_TO_NUM_OR_NULL
IPV4_STRING_TO_NUM_OR_NULL
Description
Syntax
BIGINT IPV4_STRING_TO_NUM_OR_NULL(VARCHAR ipv4_string)
BIGINT INET_ATON(VARCHAR ipv4_string)
获取包含 IPv4 地址的字符串,格式为 A.B.C.D(点分隔的十进制数字)。返回一个 BIGINT 数字,表示相应的大端 IPv4 地址。
Notice
如果输入字符串不是有效的 IPv4 地址,将返回 NULL
。该函数有一个别名为 INET_ATON
。
Example
mysql> select ipv4_string_to_num_or_null('192.168.0.1');
+-------------------------------------------+
| ipv4_string_to_num_or_null('192.168.0.1') |
+-------------------------------------------+
| 3232235521 |
+-------------------------------------------+
1 row in set (0.01 sec)
mysql> select str, ipv4_string_to_num_or_null(str) from ipv4_str;
+-----------------+---------------------------------+
|str | ipv4_string_to_num_or_null(str) |
+-----------------+---------------------------------+
| 0.0.0.0 | 0 |
| 127.0.0.1 | 2130706433 |
| 255.255.255.255 | 4294967295 |
| invalid | NULL |
+-----------------+---------------------------------+
4 rows in set (0.01 sec)
Keywords
IPV4_STRING_TO_NUM_OR_NULL, INET_ATON, IP