VeloDB Cloud
SQL Manual
SQL Functions
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)

The reverse function of IPv6NumToString, it takes an IP address String and returns an IPv6 address in binary format. If the input string contains a valid IPv4 address, returns its IPv6 equivalent.

Notice

will return 0 if the input string is not a valid IP address

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