DELIMITER $$ CREATE FUNCTION `GuidToBinary`( $Data VARCHAR(36) ) RETURNS binary(16) BEGIN DECLARE $Result BINARY(16) DEFAULT NULL; IF $Data IS NOT NULL THEN SET $Data = REPLACE($Data,’-',”);
CREATE FUNCTION `UUIDTOBIN`() RETURNS binary(16) BEGIN DECLARE my_uuid char(36); SET my_uuid = UUID(); RETURN CONCAT(UNHEX(LEFT(my_uuid,8)),UNHEX(MID(my_uuid,10,4)),UNHEX(MID(my_uuid,15,4)),UNHEX(MID(my_uuid,20,4)),UNHEX(RIGHT(my_uuid,12))); END CREATE FUNCTION `BINTOUUID`(UUID BINARY(16)) RETURNS char(36) BEGIN RETURN CONCAT(HEX(LEFT(uuid,4)),’-', HEX(MID(uuid,5,2)),’-', HEX(MID(uuid,7,2)),’-',HEX(MID(uuid,9,2)),’-',HEX(RIGHT(uuid,6))); END。