Reorder missing numbers in a sequencein two different tables using MySQL
drop procedure IF EXISTS ALTERTABLEVALUES;
delimiter $$
CREATE PROCEDURE ALTERTABLEVALUES()
BEGIN
DECLARE finished INT DEFAULT 1;
DECLARE total_count INT DEFAULT 1;
DECLARE val varchar(5);
DECLARE i INT DEFAULT 1;
DECLARE table_num INT;
DECLARE table_tab varchar(5);
DECLARE number_cursor CURSOR FOR select num,tab from tempnumbers;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET finished = 0;

drop temporary table if exists tempnumbers;
CREATE TEMPORARY TABLE tempnumbers as
select num,'temp' as tab from numbers union select num,'audit' as tab from numbers1 order by num;
SET val = (select num from tempnumbers limit 1);
SET total_count = (select count(*) from tempnumbers);

OPEN number_cursor;
get_values: LOOP
FETCH number_cursor INTO table_num,table_tab;
IF finished = 0 THEN 
 LEAVE get_values;
 END IF;
IF table_tab = 'temp' THEN 
    update numbers set numbers.num = val where numbers.num = table_num;
ELSE
    update numbers1 set numbers1.num = val where numbers1.num = table_num;
END IF;
SET val = val +1;
END LOOP get_values;
CLOSE number_cursor;
DROP TEMPORARY TABLE tempnumbers;
END;
$$
delimiter ;

After running the procedure I got numbers table as
n
--
1
2
3
5
6

and numbers1 table as 

n
--
4
7
8
9

This is how i expected for the result.