你的位置:首页 > 数据库

[数据库]MySQL 存储过程 游标例子


DROP PROCEDURE IF EXISTS mycursor; CREATE PROCEDURE mycursor() BEGIN   DECLARE v_done INT DEFAULT 0;   DECLARE v_a INT(6);   DECLARE v_b VARCHAR(20);   DECLARE cur_bak CURSOR FOR SELECT id, name FROM info;   DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET v_done = 1;   OPEN cur_bak;   REPEAT     FETCH cur_bak INTO v_a, v_b;     IF NOT v_done THEN       INSERT INTO infobak(id, name) VALUES (v_a, v_b);     END IF;   UNTIL v_done    END REPEAT;   CLOSE cur_bak; END;  CALL mycursor;  

获取【下载地址】