MySQL Procedure to retrieve missing auto increment ID of a table? -
i create procedure find out missing id table, not retrieve result, below procedure
delimiter || drop procedure if exists proc_rpt || create procedure proc_rpt() begin set @minid = (select min(`id`) `tbl_film` `user_id`=13); set @maxid = (select max(`id`) `tbl_film` `user_id`=13); repeat set @tableid = (select `id` `tbl_film` `id` = @minid); if (@tableid null) insert temp_missing(`missing_id`) values (@tableid); end if; set @minid = @minid + 1; until (@minid <= @maxid) end repeat; // earlier missing line giving error in procedure. end; ||
then call above
call rpt_proc();
but there no result on tbl_missing while can see there many missing values of film_id
in tbl_film
. please tell me doing wrong?
have try code.
delimiter || drop procedure if exists proc_rpt || create procedure proc_rpt() begin declare maxid int; declare minid int; declare curid int; select min(`id`) maxid `tbl_film` `user_id`=13; select max(`id`) minid `tbl_film` `user_id`=13; repeat select `id` curid `tbl_film` `id` = @minid); if (curid null) insert temp_missing(`missing_id`) values (curid); end if; set minid = minid + 1; until (minid <= maxid) end repeat; // earlier missing line giving error in procedure. end; ||
Comments
Post a Comment