# SHA2

Hashes the given string or binary data using the [secure hash algorithm](https://en.wikipedia.org/wiki/SHA1), version 2. As of this writing (early 2015), SHA2 is considered secure for generating collision-resistant hashes.

## Syntax

```sql
SHA2 ( plaintext, bitlen )

```

## Arguments

* plaintext: the data to hash.
* bitlen: the size of the hash to create. Currently SingleStore supports only the values 256, 384, 512, and 0 (equivalent to 256).

## Return Type

Lower case hexadecimal digits corresponding to the binary hash value.

## Examples

```sql
SELECT SHA2('ohai', 0);

```

```output

+------------------------------------------------------------------+
| SHA2('ohai', 0)                                                  |
+------------------------------------------------------------------+
| e84712238709398f6d349dc2250b0efca4b72d8c2bfb7b74339d30ba94056b14 |
+------------------------------------------------------------------+

```

```sql
SELECT SHA2('ohai', 256);

```

```output

+------------------------------------------------------------------+
| SHA2('ohai', 256)                                                |
+------------------------------------------------------------------+
| e84712238709398f6d349dc2250b0efca4b72d8c2bfb7b74339d30ba94056b14 |
+------------------------------------------------------------------+
```

```sql
SELECT SHA2('ohai', 384);

```

```output

+--------------------------------------------------------------------------------------------------+
| SHA2('ohai', 384)                                                                                |
+--------------------------------------------------------------------------------------------------+
| 2e2f6fcb70ea17cb674d7ba268026e30bde4cbe7abd74adc80d47f56ab15a5cc3e4e11e661cc22075a5b3b111bcc9afb |
+--------------------------------------------------------------------------------------------------+
```

```sql
SELECT SHA2('ohai', 512);

```

```output

+----------------------------------------------------------------------------------------------------------------------------------+
| SHA2('ohai', 512)                                                                                                                |
+----------------------------------------------------------------------------------------------------------------------------------+
| c8bd85242ad59306e2f5cd0f26c44408bf4e9a7c6b6f3f8317fd226bd131435400eff8de7b5f9927ea4aa4c0624cdd3a23630b1b5ab76207adae442e019284e5 |
+----------------------------------------------------------------------------------------------------------------------------------+
```

## Related Topics

* [SHA1](https://docs.singlestore.com/db/v9.1/reference/sql-reference/string-functions/sha-1.md)

***

Modified at: February 27, 2023

Source: [/db/v9.1/reference/sql-reference/string-functions/sha-2/](https://docs.singlestore.com/db/v9.1/reference/sql-reference/string-functions/sha-2/)

(An index of the documentation is available at /llms.txt)
