Skip to content

Instantly share code, notes, and snippets.

@kloudsamurai
Created September 5, 2019 20:22
Show Gist options
  • Save kloudsamurai/d13b3976997ef94e5d6782801f14ff64 to your computer and use it in GitHub Desktop.
Save kloudsamurai/d13b3976997ef94e5d6782801f14ff64 to your computer and use it in GitHub Desktop.
DELIMITER |
CREATE FUNCTION bin_to_uuid(b BINARY(16))
RETURNS CHAR(36) DETERMINISTIC
BEGIN
DECLARE hex CHAR(32);
SET hex = HEX(b);
RETURN CONCAT(LEFT(hex, 8), '-', MID(hex, 9,4), '-', MID(hex, 13,4), '-', MID(hex, 17,4), '-', RIGHT(hex, 12));
END
|
CREATE FUNCTION uuid_to_bin(s CHAR(36))
RETURNS BINARY(16) DETERMINISTIC
RETURN UNHEX(CONCAT(LEFT(s, 8), MID(s, 10, 4), MID(s, 15, 4), MID(s, 20, 4), RIGHT(s, 12)))
|
DELIMITER ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment