0
我創建一個過程,找出從表中缺少ID,但它並沒有取得任何結果,以下是過程MySQL檢索表的缺失自動增量ID的過程?
DELIMITER ||
DROP PROCEDURE IF EXISTS proc_rpt ||
CREATE PROCEDURE proc_rpt()
BEGIN
SET @minID = (SELECT MIN(`id`) FROM `tbl_film` WHERE `user_id`=13);
SET @maxID = (SELECT MAX(`id`) FROM `tbl_film` WHERE `user_id`=13);
REPEAT
SET @tableID = (SELECT `id` FROM `tbl_film` WHERE `id` = @minID);
IF (@tableID IS NULL) THEN
INSERT INTO temp_missing(`missing_id`) VALUES (@tableID);
END IF;
SET @minID = @minID + 1;
UNTIL (@minID <= @maxID)
END REPEAT; // earlier I was missing this line which was giving error in Procedure.
END; ||
然後我致電上述
CALL rpt_proc();
但沒有結果在tbl_missing,而我可以看到有film_id
tbl_film
有很多缺失的值。有人會告訴我我做錯了什麼嗎?