Updated on 2024-09-19 GMT+08:00

IP Functions

Description

The IPv4 function can use an IPv4 address in dotted decimal notation (example: 192.168.0.1) or an IP address in integer format (example: 3232235521). The subnet parameter is an IPv4 subnet in CIDR notation (example: 192.168.0.0/16).

IP Function Statements

Statement

Description

Example

IPV4_MATCH(address,subnet)

If subnet belongs to address, true is returned. Otherwise, false is returned. If address is not a valid IPv4 address, false is returned. This function is more efficient if address is an integer rather than a string.

SELECT IPV4_MATCH (address,subnet)

IPV4_PARSE(address)

Parses address into an integer IPv4 address. If address is a valid IPv4 address, it can be parsed. If address is not a valid IPv4 address, null is returned.

SELECT IPV4_PARSE(address)

IPV4_STRINGIFY(address)

Converts an integer address into an IPv4 address in dotted notation. If address is a valid integer IPv4 address, it can be parsed. If address is not an IPv4 address, null is returned.

SELECT IPV4_STRINGIFY(address)

Examples

IPV4_MATCH(address, subnet)

If address belongs to subnet, true is returned. Otherwise, false is returned. If address is not a valid IPv4 address, false is returned. This function is more efficient if address is an integer rather than a string.

  1. Example field

    Ipv4: 192.168.1.18

  2. Query and analysis statement
    select IPV4,IPV4_MATCH(Ipv4, '192.168.0.0/16')
  3. Query and analysis result
    Table 1 Query and analysis result

    IPV4

    EXPR$1

    192.168.1.18

    true

IPV4_PARSE(address)/IPV4_STRINGIFY(address)

Parses address into an integer IPv4 address. If address is a valid IPv4 address, it can be parsed. If address is not a valid IPv4 address, null is returned.

  1. Example field

    Ipv4: 192.168.0.1

    Num: 3232235521

  2. Query and analysis statement
    select  IPV4_PARSE(Ipv4), IPV4_STRINGIFY(Num)
  3. Query and analysis result
    Table 2 Query and analysis result

    EXPR$0

    EXPR$1

    -1062731775

    192.168.0.1