IPV6_STRING_TO_NUM

SinceVersion dev

IPV6_STRING_TO_NUM

description

Syntax

VARCHAR IPV6_STRING_TO_NUM(VARCHAR ipv6_string)

IPv6NumToString 的反向函数,它接受一个 IP 地址字符串并返回二进制格式的 IPv6 地址。 如果输入字符串包含有效的 IPv4 地址,则返回其等效的 IPv6 地址。

notice

如果输入非法的IP地址或者NULL,会抛出异常

example

  1. mysql> select hex(ipv6_string_to_num('1111::ffff'));
  2. +---------------------------------------+
  3. | hex(ipv6_string_to_num('1111::ffff')) |
  4. +---------------------------------------+
  5. | 1111000000000000000000000000FFFF |
  6. +---------------------------------------+
  7. 1 row in set (0.02 sec)
  8. mysql> select hex(ipv6_string_to_num('192.168.0.1'));
  9. +----------------------------------------+
  10. | hex(ipv6_string_to_num('192.168.0.1')) |
  11. +----------------------------------------+
  12. | 00000000000000000000FFFFC0A80001 |
  13. +----------------------------------------+
  14. 1 row in set (0.02 sec)
  15. mysql> select hex(ipv6_string_to_num('notaaddress'));
  16. ERROR 1105 (HY000): errCode = 2, detailMessage = (172.17.0.2)[CANCELLED][E33] Invalid IPv6 value
  17. mysql> select addr_src, hex(ipv6_string_to_num(addr_src)) from ipv4_string_test where addr_src is null;
  18. ERROR 1105 (HY000): errCode = 2, detailMessage = (172.17.0.2)[CANCELLED][E33] Null Input, you may consider convert it to a valid default IPv6 value like '::' first

keywords

IPV6_STRING_TO_NUM, IP