MySQL的簡單儲存過程
阿新 • • 發佈:2018-12-23
DROP PROCEDURE IF EXISTS AddPoints; delimiter // CREATE PROCEDURE AddPoints() # 後面加分號報錯 BEGIN DECLARE i int DEFAULT 10; DECLARE myflag int; DECLARE mypoints int; DECLARE mynumber BIGINT; DECLARE mydatetime Datetime; while i <= 1000000 DO SET myflag = FLOOR(RAND()*2); #返回0或者1 SET mypoints = CEIL(rand()*100); #返回1-100 SET mynumber = 13000000000+FLOOR(rand()*100000000); SET mydatetime = DATE_ADD(NOW(),INTERVAL -CEIL(rand()*10) DAY); INSERT INTO points (id,flag,point,number,time)value (i,myflag,mypoints,mynumber,mydatetime), (i+1,myflag,mypoints,mynumber,mydatetime), (i+2,myflag,mypoints,mynumber,mydatetime), (i+3,myflag,mypoints,mynumber,mydatetime), (i+4,myflag,mypoints,mynumber,mydatetime), (i+5,myflag,mypoints,mynumber,mydatetime), (i+6,myflag,mypoints,mynumber,mydatetime), (i+7,myflag,mypoints,mynumber,mydatetime), (i+8,myflag,mypoints,mynumber,mydatetime), (i+9,myflag,mypoints,mynumber,mydatetime), (i+10,myflag,mypoints,mynumber,mydatetime), (i+11,myflag,mypoints,mynumber,mydatetime), (i+12,myflag,mypoints,mynumber,mydatetime), (i+13,myflag,mypoints,mynumber,mydatetime), (i+14,myflag,mypoints,mynumber,mydatetime), (i+15,myflag,mypoints,mynumber,mydatetime), (i+16,myflag,mypoints,mynumber,mydatetime), (i+17,myflag,mypoints,mynumber,mydatetime), (i+18,myflag,mypoints,mynumber,mydatetime), (i+19,myflag,mypoints,mynumber,mydatetime); SET i =i+20; END WHILE; END // delimiter ; call AddPoints();