Skip to content

Instantly share code, notes, and snippets.

@myalban
Forked from remarkablemark/BIN_TO_UUID.sql
Created January 2, 2022 22:02
Show Gist options
  • Save myalban/e78ae7e7edc2059d9b7ac394cbc191f4 to your computer and use it in GitHub Desktop.
Save myalban/e78ae7e7edc2059d9b7ac394cbc191f4 to your computer and use it in GitHub Desktop.
DELIMITER //
CREATE FUNCTION BIN_TO_UUID(bin BINARY(16))
RETURNS CHAR(36) DETERMINISTIC
BEGIN
DECLARE hex CHAR(32);
SET hex = HEX(bin);
RETURN LOWER(CONCAT(LEFT(hex, 8), '-', MID(hex, 9, 4), '-', MID(hex, 13, 4), '-', MID(hex, 17, 4), '-', RIGHT(hex, 12)));
END; //
DELIMITER ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment