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

# `sha2` 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

Returns a checksum of the `SHA-2` family as a hex string of `expr`.

## Syntax

```
sha2(expr, bitLength)
```

## Arguments

* `expr`: A `BINARY` or `STRING` expression.
* `bitLength`: An `INTEGER` expression.

## Returns

A STRING.

`bitLength` can be 0, `224`, `256`, `384`, or `512`.
`bitLength` 0 is equivalent to `256`.

## Examples

```sql
>> SELECT sha2('Spark', 256);
  529bc3b07127ecb7e53a4dcf1991d9152c24537d919178022b2c42657f79a26b
```

## Related functions

* [`mask` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/mask.md)
* [`sha` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/sha.md)
* [`sha1` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/sha1.md)
* [`crc32` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/crc32.md)
* [`md5` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/md5.md)
* [`hash` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/hash.md)
