用MySQL 產生隨機密碼-增加大寫處理

來源:互聯網
上載者:User

前面寫過寫過:

這次增加了大寫字母的處理。

  1. DELIMITER $$  
  2.   
  3. USE `t_girl`$$  
  4.   
  5. DROP FUNCTION IF EXISTS `func_rand_string`$$  
  6.   
  7. CREATE DEFINER=`root`@`localhost` FUNCTION `func_rand_string`(f_num TINYINT UNSIGNED,f_type TINYINT UNSIGNED) RETURNS VARCHAR(32) CHARSET utf8  
  8. BEGIN  
  9.       -- Translate the number to letter.   
  10.       -- No 1 stands for string only.   
  11.       -- No 2 stands for number only.   
  12.       -- No 3 stands for combination of the above.   
  13.       DECLARE i INT UNSIGNED DEFAULT 0;  
  14.       DECLARE v_result VARCHAR(255) DEFAULT '';  
  15.       WHILE i < f_num DO  
  16.         IF f_type = 1 THEN  
  17.           SET v_result = CONCAT(v_result,CHAR(65+32*(CEIL(RAND()*2)-1)+CEIL(RAND()*25)));  
  18.         ELSEIF f_type=2 THEN  
  19.           SET v_result = CONCAT(v_result,CEIL(RAND()*9));  
  20.         ELSEIF f_type=3 THEN  
  21.           IF (CEIL(RAND()*2)-1) = 1 THEN  
  22.             SET v_result = CONCAT(v_result,SUBSTRING(REPLACE(UUID(),'-',''),i+1,1));  
  23.           ELSE   
  24.             SET v_result = CONCAT(v_result,UPPER(SUBSTRING(REPLACE(UUID(),'-',''),i+1,1)));  
  25.           END IF;  
  26.         END IF;  
  27.         SET i = i + 1;  
  28.       END WHILE;   
  29.       RETURN v_result;  
  30.     END$$  
  31.   
  32. DELIMITER ;  

調用方法類似。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.