Free To Feel

Heading to entrepreneur.


Joshua Chi
Github

MySQL Custom Function

Today when I try to update a table in sql command, I didn't want to use the mysql function uuid to generate a string with middle line in it. So I try to use mysql custom function to generate a 32-bit length string without middle line.

DELIMITER ;

DROP FUNCTION IF EXISTS uid;
DELIMITER $$

CREATE FUNCTION uid()
    RETURNS VARCHAR(32)
BEGIN
    DECLARE c VARCHAR(36) DEFAULT '';
    SET c = uuid();
    return CONCAT(substring(c,1,8) , substring(c,10,4) , substring(c,15,4) , substring(c,20,4), substring(c,25,12));
END$$

DELIMITER ;

select uid();

I am writing this because mysql is powerful enough to handle all the issues in web software development.

comments powered by Disqus