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)

获取包含 IPv4 地址的字符串,格式为 A.B.C.D(点分隔的十进制数字)。返回一个 BIGINT 数字,表示相应的大端 IPv4 地址。

notice

如果输入字符串不是有效的 IPv4 地址或者NULL,将返回0

example

  1. mysql> select ipv4_string_to_num_or_default('192.168.0.1');
  2. +----------------------------------------------+
  3. | ipv4_string_to_num_or_default('192.168.0.1') |
  4. +----------------------------------------------+
  5. | 3232235521 |
  6. +----------------------------------------------+
  7. 1 row in set (0.01 sec)
  8. mysql> select str, ipv4_string_to_num_or_default(str) from ipv4_str;
  9. +-----------------+------------------------------------+
  10. |str | ipv4_string_to_num_or_default(str) |
  11. +-----------------+------------------------------------+
  12. | 0.0.0.0 | 0 |
  13. | 127.0.0.1 | 2130706433 |
  14. | 255.255.255.255 | 4294967295 |
  15. | invalid | 0 |
  16. +-----------------+------------------------------------+
  17. 4 rows in set (0.01 sec)
  18. mysql> select addr_src, ipv4_string_to_num_or_default(addr_src) from ipv4_string_test where addr_src is null;
  19. +----------+-----------------------------------------+
  20. | addr_src | ipv4_string_to_num_or_default(addr_src) |
  21. +----------+-----------------------------------------+
  22. | NULL | 0 |
  23. +----------+-----------------------------------------+
  24. 1 row in set (0.09 sec)

keywords

IPV4_STRING_TO_NUM_OR_DEFAULT, IP