V6_SUBNETN
Calculates a subnet address in CIDR (Classless Inter-Domain Routing) format from a varbinary or alphanumeric IPv6 address.
Behavior Type
Syntax
V6_SUBNETN ( expression1, expression2 )
Parameters
expression1 |
( Notes:
|
expression2 |
( |
Notes
The following syntax masks a BINARY
IPv6 address B so that the N left-most bits of S form a subnet address, while the remaining right-most bits are cleared.
V6_SUBNETN
right-pads B to 16 bytes with zeros, if necessary and masks B, preserving its N-bit subnet prefix.
=> V6_SUBNETN(VARBINARY B, INT8 N) -> VARBINARY(16) S
If B is NULL or longer than 16 bytes, or if N is not between 0 and 128 inclusive, the result is NULL.
S = [B]/N in Classless Inter-Domain Routing notation (CIDR notation).
The following syntax masks an alphanumeric IPv6 address A so that the N leftmost bits form a subnet address, while the remaining rightmost bits are cleared.
=> V6_SUBNETN(VARCHAR A, INT8 N) -> V6_SUBNETN(V6_ATON(A), N) -> VARBINARY(16) S
Example
This example returns VARBINARY
, after using V6_ATON
to convert the VARCHAR
string to VARBINARY
:
=> SELECT V6_SUBNETN(V6_ATON('2001:db8::8:800:200c:417a'), 28); v6_subnetn --------------------------------------------------------------- \001\015\260\000\000\000\000\000\000\000\000\000\000\000\000