Declaration
BIN_TO_UUID(binary_uuid), BIN_TO_UUID(binary_uuid,swap_flag)
Description
The BIN_TO_UUID() function converts a binary UUID to a string UUID and returns the result. The binary value binary_uuid must be a UUID of the VARBINARY(16) data type. The return value is a UUID version 1 value, which is a 128-bit number represented as a utf8mb3 string consisting of five hexadecimal groups separated by hyphens. The format is the same as that of the UUID() function: aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeeee. The description is as follows:
- The first three digits are generated from the low, middle, and high parts of the timestamp. The high part also includes the UUID version number.
- The fourth digit ensures the uniqueness of the timestamp, preventing ambiguity when the timestamp value may lose uniqueness due to factors such as daylight saving time.
- The fifth digit is the IEEE 802 node number that provides spatial uniqueness. If this number is unavailable, a random number is used instead, but spatial uniqueness cannot be guaranteed.
If the UUID parameter is NULL, the return value is NULL. An error occurs if any parameter is invalid.
The syntax for BIN_TO_UUID() includes both single-parameter and two-parameter forms, as described below:
- The binary UUID value is specified using a single parameter. The UUID value is assumed not to have its low and high time parts swapped. The returned string result follows the same order as the binary parameters.
- The binary UUID value and the
swap-flagvalue are specified in the dual-parameter form:- If
swap_flagis 0, the two-parameter form is equivalent to the single-parameter form. The string result has the same order as the binary parameters. - If
swap_flagis 1, it is assumed that the UUID value has had its low and high time parts swapped. These parts are swapped back to their original positions in the resulting value.
- If
BIN_TO_UUID() is the inverse function of UUID_TO_BIN(). For information about usage examples and the rule for swapping time parts, see UUID_TO_BIN().