标签 mysql 下的文章

delimiter $$
CREATE PROCEDURE create_password2()
BEGIN
declare s varchar(62) default 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
DECLARE n,r1,r2,r3,r4,r5,r6 INT DEFAULT 1;
DECLARE str varchar(255) default '';
set r1=floor(1+rand()*3);
while r1<63
do

 set r2=floor(1+rand()*3);
 while r2<63
 do 
   set r3=floor(1+rand()*3);
   while r3<63
   do
     set r4=floor(1+rand()*3); 
     while r4<63
     do 
       set r5=floor(1+rand()*3);
       while r5<63
       do
         set r6=floor(1+rand()*3); 
         while r6<63
         do 
           set str=concat(substring(s,r1,1) ,substring(s,r2,1) ,substring(s,r3,1) ,substring(s,r4,1) ,substring(s,r5,1) ,substring(s,r6,1) );
           INSERT INTO dgq_password(password_clear,password_sha1) VALUES(str,password(str));
         set r6=r6+4;
         end while;
       set r5=r5+4;
       end while;
     set r4=r4+4;
     end while;
   set r3=r3+4;
   end while;
 set r2=r2+4;
 end while;

set r1=r1+3;
end while;

END$$
DELIMITER ;

delimiter $$
drop function if exists rand_string;
create function rand_string(n int) returns varchar(255) CHARSET utf8
begin
declare chars_str varchar(62) default 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
declare return_str varchar(255) default '';
declare i int default 0;
while i<n do
set return_str=concat(return_str,substring(chars_str,floor(1+rand()*62),1));
set i=i+1;
end while;
return return_str;
end$$
DELIMITER ;