Created
September 8, 2015 09:13
-
-
Save mdaley/a0d1f5d3393756ac0530 to your computer and use it in GitHub Desktop.
mysql random pin generation function
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
drop function if exists randalpha; | |
create function randalpha (s varchar(100)) | |
returns char(1) | |
return substring(s, floor (rand() * length(s) + 1), 1); | |
drop function if exists randpin; | |
delimiter // | |
create function randpin(l int, r varchar(100)) | |
returns varchar(100) | |
begin | |
declare i int; | |
declare pin varchar(100); | |
set pin = ''; | |
set i = 1; | |
while i <= l do | |
set pin = concat(pin,randalpha(r)); | |
set i = i + 1; | |
end while; | |
return pin; | |
end// | |
delimiter ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment