SHA256 function
Computes the SHA-256 hash of a string or binary value and returns the result as a binary value (VARBINARY).
Syntax
SHA256(expression)
Arguments
expression: AVARCHARexpression to hash.
Returns
A VARBINARY containing the SHA-256 hash.
Examples
-- Example 1: Get hexadecimal representation
> SELECT TO_HEX(SHA256(''));
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
> SELECT TO_HEX(SHA256('a b c d'));
'f82ce1b653e30b1ceb5711bbf75965dd24513011d7daa48bbd8610550154a1fd'
-- Example 2: Hash UTF-8 strings
> SELECT TO_HEX(SHA256('abcABCжщфЖЩФ'));
'b0c486d0434e078fa1ff8fc23bf984bc41dd31d2e95ca69a427ddbbb56b29fc2'
-- Example 3: Hash binary data does not work, only VARCHAR input is allowed
> SELECT SHA256(x'000102030405');
ERROR
Notes
SHA-256 produces a 256-bit (32-byte) hash.
The same input always produces the same output (deterministic).
SHA-256 is a cryptographic hash function suitable for security-sensitive applications.
Use
TO_HEX()to convert the binary result to a readable hexadecimal string.
See Also
TO_HEX function - Convert binary to hexadecimal