oracle游标循环插⼊表,利⽤游标先遍历表数据,再根据循环插
⼊数据
DELIMITER $$
CREATE PROCEDURE `batchCall`()
oracle游标的使用BEGIN
DECLARE id VARCHAR(32);
DECLARE create_time VARCHAR(255);
DECLARE done INT DEFAULT 0;
DECLARE done2 INT ;
DECLARE edu_id VARCHAR(255) DEFAULT '';
DECLARE edu_ip VARCHAR(255);
DECLARE rs CURSOR FOR (SELECT t.id AS edu_id,t.edu_ip AS edu_ip FROM cap_edu t);
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN rs;
myloop:LOOP
FETCH FROM rs INTO edu_id,edu_ip;
IF done = 1 THEN
LEAVE myloop;
END IF;
SET done2 = 0;
my2loop:LOOP
IF done2 >= 100 THEN
LEAVE my2loop;
END IF;
SET id = REPLACE(UUID(),'-','');
SELECT RandomDateTime(DATE_FORMAT('2016-8-1 00:00:00','%Y-%m-%d %H:%i:%s'),DATE_FORMAT('2016-10-31
23:59:59','%Y-%m-%d %H:%i:%s')) INTO create_time;
INSERT INTO edu_performance_data VALUES (id, done2, NULL, NULL, NULL, NULL, NULL, NULL, create_time, edu_id,
edu_ip, 1, NULL, NULL, NULL, NULL, NULL, NULL);
SET done2 = done2+1;
END LOOP my2loop;
END LOOP myloop;
CLOSE rs;
END$$
DELIMITER ;
DELIMITER $$
CREATE
FUNCTION `RandomDateTime`(sd DATETIME,ed DATETIME)
RETURNS DATETIME
BEGIN
RETURN DATE_ADD(sd,INTERVAL FLOOR(1+RAND()*((ABS(UNIX_TIMESTAMP(ed)-UNIX_TIMESTAMP(sd)))-1)) SECOND); END$$
DELIMITER ;

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。