Created
March 6, 2023 18:37
-
-
Save ano/36d295cbee12c3ccc5ac0cddd2900af9 to your computer and use it in GitHub Desktop.
a MySQL user defined function that takes in a number and uses it to generate a guid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# a MySQL user defined function that takes in a number and uses it to generate a guid | |
CREATE FUNCTION generateGuid(num INT) RETURNS CHAR(32) | |
BEGIN | |
DECLARE guid CHAR(32); | |
SET guid = CONCAT( | |
SUBSTR(SHA1(RAND()), 1, 8), '-', | |
SUBSTR(SHA1(RAND()), 1, 4), '-', | |
SUBSTR(SHA1(RAND()), 1, 4), '-', | |
SUBSTR(SHA1(RAND()), 1, 4), '-', | |
IF(LENGTH(num)>12, SUBSTR(SHA1(RAND()), 1, 12), CONCAT(REPEAT('0', 12-LENGTH(num)),num ) ) | |
); | |
RETURN guid; | |
END; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment