> ## Documentation Index
> Fetch the complete documentation index at: https://docs.e6data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SHA2

> Computes a SHA-2 digest using the selected bit length.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Scalar function</span></div>

Returns NULL when either argument is NULL or bit\_length is unsupported.

## Syntax

### Scalar

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
sha2(value, bit_length)
```

## Arguments

| Name | Type | Required | Description |
| - | - | - | - |
| value | STRING or BINARY | Yes | The bytes to hash; strings use their UTF-8 bytes. |
| bit\_length | INTEGER | Yes | The SHA-2 digest size in bits. 0, 224, 256, 384 or 512; 0 selects 256. |

## Returns

* Type: STRING
* Possible values: A lowercase hexadecimal digest of 56, 64, 96 or 128 characters for 224, 256, 384 or 512 bits.
* NULL behavior: Returns NULL when either argument is NULL or bit\_length is unsupported.

## Properties

| Property | Value |
| - | - |
| Deterministic | Yes |
| Supports window usage | No |
| Exact result | Yes |

## Usage notes

* The bit length may vary by row; it is not required to be a constant expression.

## Examples

### Value and NULL input

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT sha2('abc', 256) AS digest, sha2('abc', 0) AS zero_selects_256, sha2('abc', 123) AS invalid_size;
```

| digest | zero\_selects\_256 | invalid\_size |
| - | - | - |
| ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad | ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad | NULL |

### Choose a digest size

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT sha2('abc', 224) AS digest_224;
```

| digest\_224 |
| - |
| 23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7 |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.