2. SQL Data Types : Data Types : IP Network Address Data Types
 
Share this page                  
IP Network Address Data Types
IPV4 and IPV6 are abstract data types that store IPv4 and IPv6 host addresses, respectively, in binary format.
IPV4 is a 4-byte host address in dotted-decimal notation (four decimal numbers, each ranging from 0 to 255, separated by dots). For example: 172.16.254.1.
IPV6 is a 16-byte host address in eight groups of four hexadecimal digits separated by colons. For example: 2001:0db8:85a3:0042:1000:8a2e:0370:7334.
We recommend using the IPV4 and IPV6 data types instead of plain text to store network addresses because they provide input error checking and specialized operators and functions.
An IPv4 address can be stored in an IPv6-type value, but the address will be stored as an IPv4-mapped IPv6 address. When coerced to type IPV6, a "pure" IPv4 address cannot be distinguished from a mapped IPv4 address—for example, "192.168.0.1" cannot be distinguished from "::ffff:c0a8:1" or from "::ffff:192.168.0.1".
Comparisons between two IPV4 or two IPV6 values operate like BYTE comparisons (that is, unsigned byte-wise). IPV6 is the "higher" type in mixed expressions.
IPV4 and IPV6 addresses are stored as 4 and 16 bytes, respectively.
Note:  CIDR notation (for example: 192.168.100.0/24) is not supported.
Example input and output:
IPV4 or IPV6 Input
Output
172.16.254.1
172.16.254.1
2001:db8:0:1234:0:567:8:1
2001:db8:0:1234:0:567:8:1
2001:db8:0:0:0:0:0:0
2001:db8::
::ffff:c0a8:1
192.168.0.1