refactor: 合并sql

This commit is contained in:
Captain.B 2021-05-24 16:25:07 +08:00 committed by 刘瑞斌
parent 6035c6fdbe
commit 7c3b13dab4
1 changed files with 0 additions and 50 deletions

View File

@ -1,50 +0,0 @@
alter table issues add num int null;
DROP PROCEDURE IF EXISTS test_cursor;
DELIMITER //
CREATE PROCEDURE test_cursor()
BEGIN
DECLARE projectId VARCHAR(64);
DECLARE issueId VARCHAR(64);
DECLARE num INT;
DECLARE done INT DEFAULT 0;
DECLARE cursor1 CURSOR FOR (SELECT DISTINCT project_id
FROM issues
WHERE num IS NULL);
DECLARE cursor2 CURSOR FOR (SELECT id
FROM issues
WHERE project_id = projectId
ORDER BY create_time);
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cursor1;
outer_loop:
LOOP
FETCH cursor1 INTO projectId;
IF done
THEN
LEAVE outer_loop;
END IF;
SET num = 100001;
OPEN cursor2;
inner_loop:
LOOP
FETCH cursor2 INTO issueId;
IF done
THEN
LEAVE inner_loop;
END IF;
UPDATE issues
SET num = num
WHERE id = issueId;
SET num = num + 1;
END LOOP;
SET done = 0;
CLOSE cursor2;
END LOOP;
CLOSE cursor1;
END //
DELIMITER ;
CALL test_cursor();
DROP PROCEDURE IF EXISTS test_cursor;