Skip to content

Instantly share code, notes, and snippets.

@IcyMidnight
IcyMidnight / MySQL functions to convert between binary and string uuids
Created July 31, 2009 09:27
MySQL functions to convert between binary and string uuids
DELIMITER |
CREATE FUNCTION uuid_from_bin(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
|