列"时间戳" (table:rand_numbers")在每一行中都有相同的时间戳:
2016-09-26 00:00:13
2016-09-26 00:00:13
2016-09-26 00:00:13
2016-09-26 00:00:13
我想在每一行添加1分钟,结果是:
2016-09-26 00:00:13
2016-09-26 00:01:13
2016-09-26 00:02:13
2016-09-26 00:03:13
这不起作用:
CREATE PROCEDURE myproc()
BEGIN
DECLARE i int DEFAULT 1;
WHILE i <= 10 DO
INSERT INTO rand_numbers (timestamp)
VALUES ('2016-09-26 00:00:13' + INTERVAL 1 MINUTE);
SET i = i + 1;
END WHILE;
END
答案 0 :(得分:0)
只需使用循环插入
DELIMITER //
CREATE PROCEDURE myproc()
BEGIN
DECLARE count INT DEFAULT 0;
DECLARE max INT DEFAULT 10;
WHILE(count < max) DO
INSERT INTO rand_numbers (timestamp) VALUES ('2016-09-26 00:00:13' + INTERVAL count MINUTE);
SET count = count + 1;
END WHILE;
END//
DELIMITER ;
使用run call myproc();
答案 1 :(得分:0)
试试这个
DECLARE @intFlag INT
DECLARE @VALUE DATETIME
SET @intFlag = 1
SET @VALUE = CURRENT_TIMESTAMP
--print @VALUE
WHILE (@intFlag <=5)
BEGIN
PRINT (DATEADD(minute,1,@VALUE));
SET @VALUE = (DATEADD(minute,1,@VALUE));
SET @intFlag = @intFlag + 1
CONTINUE;
END