Created
April 19, 2017 08:09
-
-
Save Hotfirenet/6059aa528800c1bb944fa5b7d8fcbf42 to your computer and use it in GitHub Desktop.
Fonction MySQL qui permet de generer une chaine de caractère aléatoirement
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
/* Find on http://ready2gosoft.com/php/mysql-generate-random-string.html | |
USE SELECT genstring(ROUND((RAND() * (128-1))+1)); | |
USE SELECT CONCAT(genstring(ROUND((RAND() * (30-5))+5)), '@', genstring(ROUND((RAND() * (30-5))+5)), '.', genstring(ROUND((RAND() * (5-2))+2))); | |
*/ | |
DROP function if exists genstring; | |
delimiter $$ | |
CREATE FUNCTION genstring(in_strlen int) RETURNS VARCHAR(500) DETERMINISTIC | |
BEGIN | |
set @var:=''; | |
while(in_strlen>0) do | |
set @var:=concat(@var,ELT(1+FLOOR(RAND() * 26), 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z')); | |
set in_strlen:=in_strlen-1; | |
end while; | |
RETURN @var; | |
END $$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment