Returns the SHA-1 hash of a STRING or BINARY expression as a 40-character lowercase hexadecimal string.
Syntax
string sha(string|binary <expr>)
Parameters
expr: Required. The STRING or BINARY value to hash.
Return value
Returns a STRING value: a 40-character lowercase hexadecimal string representing the 160-bit SHA-1 digest. Returns null if expr is null.
Usage notes
SHA-1 is suitable for checksums and data integrity verification, not for cryptographic security. For security-sensitive use cases, use sha2 with a stronger digest length (256 or 512 bits).
Do not use sha to encrypt data that you need to decrypt. SHA-1 has no corresponding decryption function.
Examples
Example 1: Compute the SHA-1 hash of the string ABC.
select sha('ABC');
-- Returns: 3c01bdbb26f358bab27f267924aa2c9a03fcfdb8
Example 2: Pass a null value.
select sha(null);
-- Returns: null
Related functions
For other hash and encoding functions, see Other functions.