SHA512 Function

Overview

The SHA512 function computes the SHA-512 hash value for a given string. SHA-512 is a variant of the SHA-2 family of hash algorithms that can map arbitrary-length data to a fixed-length (512-bit) hash value, outputting a 128-character hexadecimal string.

Syntax

sha512(expr)

Parameters

  • expr: The input data for which to compute the SHA-512 hash value. Supports STRING, VARCHAR, CHAR, and BINARY types.

Return Result

Returns a STRING type value representing the computed 128-character hexadecimal hash string.

Examples

  1. Compute the SHA-512 value of a simple string:

    SELECT sha512('hello') AS res; +----------------------------------------------------------------------------------------------------------------------------------+ | res | +----------------------------------------------------------------------------------------------------------------------------------+ | 9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043 | +----------------------------------------------------------------------------------------------------------------------------------+

  2. Compute the SHA-512 value of a string containing special characters:

    SELECT sha512('Hello, World!') AS res; +----------------------------------------------------------------------------------------------------------------------------------+ | res | +----------------------------------------------------------------------------------------------------------------------------------+ | 374d794a95cdcfd8b35993185fef9ba368f160d8daf432d08ba9f1ed1e5abe6cc69291e0fa2fe0006a52570ef18c19def4e617c33ce52ef0a6e5fbe318cb0387 | +----------------------------------------------------------------------------------------------------------------------------------+

  3. When the input is NULL:

    SELECT sha512(NULL) AS res; +------+ | res | +------+ | NULL | +------+

Notes

  • SHA-512 hash values are irreversible, meaning the original data cannot be derived from the hash value.
  • SHA-512 outputs a fixed 128-character hexadecimal string (512 bits).
  • When the input parameter is NULL, the result is NULL.
  • SHA-512 belongs to the SHA-2 family of algorithms, with higher security than SHA-1, providing stronger security than SHA-256, suitable for data integrity verification and other scenarios requiring higher security.