---
title: Network Type Functions
slug: PLH7ZlLVP8ujIBx8s5ocU
description: Manage and analyze network data using network type functions in Ocient.
docTags: 
createdAt: Fri Apr 19 2024 21:43:09 GMT+0000 (Coordinated Universal Time)
updatedAt: Mon Mar 30 2026 18:52:29 GMT+0000 (Coordinated Universal Time)
---

The Ocient® System supports these functions for `IP` and `IPV4` data types.

## IP&#x20;

Casts the `IPV4` data type to the `IP` data type. The returned value is the IPv6-mapped IPv4 address.

**Syntax**

```sql
IP(ipv4_col)
```

| **Argument** | **Data Type**     | **Description**                             |
| ------------ | ----------------- | ------------------------------------------- |
| `ipv4_col`   | `CHAR` or `IPV4`  | IP address in the `IPV4` data type to cast. |

**Example**

Cast the IPv4 address `128.1.2.3` to the IPv6-mapped IPv4 address.

```sql
SELECT IP(IPV4('128.1.2.3'));
```

*Output*

```none
ip(ipv4(('128.1.2.3')))                        
-----------------------------------------------
128.1.2.3 

Fetched 1 row
```

## IPV4

Returns the IPv4 portion of the IPv6 address.

You can only cast the IP data type to IPv4 if the IPv6 value has an IPv4 semantic equivalent. The database can convert these IPv6 address formats to IPv4:

- IPv4-compatible IPv6 `::x.x.x.x`
- IPv6-mapped IPv4 `::ffff:x.x.x.x`
- NAT64-prefixed `64:ff9b::x.x.x.x`

**Syntax**

```sql
IPV4(ip_col)
```

| **Argument** | **Data Type** | **Description**                                                                                                                                                                                        |
| ------------ | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `ip_col`     | `IP`          | IPv6-mapped IP address in the `IP` data type to cast.<br /><br />If the IPv6 address is not IPv4-compatible, IPv6-mapped, or NAT64-prefixed, the cast returns an `INVALID DATA TYPE CONVERSION` error. |

**Example**

Cast the IPv6-mapped IP address `::ffff:128.1.2.3` to the `IPV4` data type. Return the IPv4 portion of the address.

```sql
SELECT IPV4(IP('::ffff:128.1.2.3'));
```

*Output*

```none
ipv4(ip(('::ffff:128.1.2.3'))) 
-------------------------------
128.1.2.3 

Fetched 1 row
```

## IS\_IPV4

The `IS_IPV4` function tests whether the database can convert the `IP` value to the `IPV4` data type. The database can convert these IPv6 address formats to IPv4:

- IPv4-compatible IPv6 `::x.x.x.x`
- IPv6-mapped IPv4 `::ffff:x.x.x.x`
- NAT64-prefixed `64:ff9b::x.x.x.x`

The function returns a Boolean value (`true` or `false`) that indicates whether the conversion works from the specified IP address to the IPv4 address.

**Syntax**

```sql
IS_IPV4(ip_col)
```

| **Argument** | **Data Type** | **Description**                                         |
| ------------ | ------------- | ------------------------------------------------------- |
| `ip_col`     | `IP`          | Specified IP address for conversion to an IPv4 address. |

**Example**

Determine whether the `::fffe:128.1.2.3` string is a valid IPv4 address. Use the `IP` function to cast the string as an IP address.

```sql
SELECT IS_IPV4(IP('::fffe:128.1.2.3'));
```

*Output*

```none
is_ipv4_convertible(ip(('::fffe:128.1.2.3'))) 
----------------------------------------------
false 

Fetched 1 row
```

## SUBNET

The `SUBNET` function computes the prefix from an `IP` or `IPV4` value and the size of the prefix. The function returns a value of the same type as the `ip_col` argument.

**Syntax**

```sql
SUBNET(ip_col, prefix_size)
```

| **Argument**  | **Data Type**  | **Description**                                                                                                                                                                                                                                                   |
| ------------- | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ip_col`      | `IP` or `IPV4` | The IP address for the prefix calculation.                                                                                                                                                                                                                        |
| `prefix_size` | Integer        | The size of the subnet network prefix. For `IPV4` addresses, the size must be in the range \[0, 32], and for `IP` addresses, the size must be in the range \[0, 128]. If the prefix exceeds these range values, the function returns an `INVALID ARGUMENT` error. |

**Example**

Calculate the prefix for the NAT64-prefixed IP address `64:ff9b::128.2.3.4` with prefix size `98`. Use the `IP` function to cast the string as an IP address.

```sql
SELECT SUBNET(IP('64:ff9b::128.2.3.4'), 98);
```

*Output*

```none
subnet(ip(('64:ff9b::128.2.3.4')), (98))       
-----------------------------------------------
64:ff9b:0:0:0:0:8000:0 

Fetched 1 row
```

## Related Links

[Data Types](<./Data Types.md>)



