SelectDB Cloud
SQL 手册
SQL 函数
IP Functions
IPV6_STRING_TO_NUM_OR_DEFAULT

IPV6_STRING_TO_NUM_OR_DEFAULT

IPV6_STRING_TO_NUM_OR_DEFAULT

Description

Syntax

VARCHAR IPV6_STRING_TO_NUM_OR_DEFAULT(VARCHAR ipv6_string)

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

Notice

如果输入非法的IP地址,会返回 0

Example

mysql> select hex(ipv6_string_to_num_or_default('1111::ffff'));
+--------------------------------------------------+
| hex(ipv6_string_to_num_or_default('1111::ffff')) |
+--------------------------------------------------+
| 1111000000000000000000000000FFFF                 |
+--------------------------------------------------+
1 row in set (0.01 sec)
 
mysql> select hex(ipv6_string_to_num_or_default('192.168.0.1'));
+---------------------------------------------------+
| hex(ipv6_string_to_num_or_default('192.168.0.1')) |
+---------------------------------------------------+
| 00000000000000000000FFFFC0A80001                  |
+---------------------------------------------------+
1 row in set (0.02 sec)
 
mysql> select hex(ipv6_string_to_num_or_default('notaaddress'));
+---------------------------------------------------+
| hex(ipv6_string_to_num_or_default('notaaddress')) |
+---------------------------------------------------+
| 00000000000000000000000000000000                  |
+---------------------------------------------------+
1 row in set (0.02 sec)

Keywords

IPV6_STRING_TO_NUM_OR_DEFAULT, IP

© 2023 北京飞轮数据科技有限公司 京ICP备2022004029号 | Apache、Apache Doris 以及相关开源项目名称均为 Apache 基金会商标