BEGIN
DECLARE done INT DEFAULT 0 ;
DECLARE examId VARCHAR (40) ;
DECLARE cur CURSOR FOR SELECT f_id FROM `exam`.t_exam;
DECLARE CONTINUE HANDLER FOR NOT found SET done = 1 ;
DELETE FROM `report`.`t_exam_pass_member` WHERE f_id LIKE 'bigdata%';
OPEN cur ;
loop_xxx : LOOP
FETCH cur INTO examId ;
IF done = 1 THEN
LEAVE loop_xxx ;
END IF ;
INSERT INTO `report`.`t_exam_pass_member` (`f_id`, `f_exam_id`, `f_pass_member`, `f_company_id`, `f_create_time`, `f_version`)
SELECT concat('bigdata',examId), examId, '3', '1', UNIX_TIMESTAMP() * 1000, 1 ;
COMMIT;
END LOOP;
CLOSE cur ;
END
来源:https://www.cnblogs.com/lipengsheng-javaweb/p/11770921.html