Skip to content

Instantly share code, notes, and snippets.

@theking2
Created March 30, 2024 16:10
Show Gist options
  • Save theking2/39a930277f5fe5c5f7a0c5dca297bb21 to your computer and use it in GitHub Desktop.
Save theking2/39a930277f5fe5c5f7a0c5dca297bb21 to your computer and use it in GitHub Desktop.
BIN_TO_UUID
CREATE FUNCTION `BIN_TO_UUID`(b binary(16))
RETURNS char(36) CHARSET ascii
BEGIN
DECLARE hexStr CHAR(32);
SET hexStr = HEX(b);
RETURN LOWER(CONCAT(
SUBSTR(hexStr, 25, 12), '-',
SUBSTR(hexStr, 21, 4), '-',
SUBSTR(hexStr, 13, 4), '-',
SUBSTR(hexStr, 17, 4), '-',
SUBSTR(hexStr, 1, 12)
));
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment