---
title: unhex function
description: Learn the syntax of the unhex function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/unhex
---

# `unhex` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime

Converts hexadecimal `expr` to BINARY.

## Syntax

```
unhex(expr)
```

## Arguments

* `expr`: A STRING expression of hexadecimal characters.

## Returns

The result is BINARY.

If the length of `expr` is odd, the first character is discarded and the result is padded with a null byte.
If `expr` contains non hex characters the result is NULL.

## Examples

```sql
> SELECT decode(unhex('537061726B2053514C'), 'UTF-8');
 Spark SQL
```

## Related functions

* [`hex` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/hex.md)
