已知表
向该表中插入指定次数的随机字符串:
代码如下:
DROP PROCEDURE sc //
CREATE PROCEDURE sc(num INT)
BEGIN
DECLARE str VARCHAR(26) DEFAULT "abcdefghijklmnopqrstuvwxyz";
DECLARE cnt INT DEFAULT 0;
DECLARE startIndex INT DEFAULT 1;
DECLARE len INT DEFAULT 1;
SET startIndex = FLOOR(RAND()*26+1);
SET len = FLOOR(RAND()*ABS((20-startIndex+1))+1);
WHILE cnt < num DO
SET cnt = cnt + 1;
INSERT INTO stringcontent (content) VALUES (SUBSTR(str,FLOOR(RAND()*26+1),len));
END WHILE ;
END //
CALL sc(20) //
SELECT * FROM stringcontent //