MYSQL遊標的使用
有問題,要檢查一下:
DELIMITER |
CREATE PROCEDURE sortTable()BEGIN
DECLARE val INT;
SET val = 1;
DECLARE curTable CURSOR FOR SELECT * FROM t_ruanko_ke_answer ORDER BY qid ASC;
/*遊標 異常後 捕捉 並設定 迴圈使用 變數 tmpname 為 null 跳出迴圈。*/
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET tmpname = NULL;
/*開遊標*/
OPEN curTable;
/*遊標向下走一步*/
FETCH curTable INTO tmpName;
WHILE( tmpname IS NOT NULL ) DO
UPDATE t_ruanko_ke_answer SET id = val;
SET val = val+1;
FETCH curTable INTO tmpName;
END WHILE;
CLOSE curTable;
END|