Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. DELIMITER $$
  2. CREATE DEFINER=`root`@`localhost` FUNCTION `random_str`() RETURNS char(16) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci
  3. BEGIN
  4. DECLARE chars varchar(16);
  5. DECLARE rs varchar(16);
  6. SET rs = '';
  7. SET chars = 'ABCDEF1234567890';
  8. WHILE (LENGTH(rs) < 16) DO
  9. SET rs = CONCAT(rs, SUBSTRING(chars, RAND() * LENGTH(chars), 1));
  10. END WHILE;
  11. RETURN rs;
  12. END$$
  13.  
  14.  
  15. CREATE DEFINER=`root`@`localhost` PROCEDURE `fill_test`(IN `cnt` INT UNSIGNED)
  16. NO SQL
  17. BEGIN
  18. DECLARE c int;
  19. DECLARE rs varchar(16);
  20. SET c = 0;
  21. while (c < cnt) DO
  22. set rs = random_str();
  23. INSERT INTO test_random_binary_codes (hash) VALUES (rs);
  24. set c = c + 1;
  25. end while;
  26. END$$
  27.  
  28.  
  29. DELIMITER ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement