drop procedure if exists my_procedure;
delimiter $
create procedure my_procedure()
begin
declare row_cat_id int;
declare row_cat_id_org int;
declare row_cat_name varchar(90);
declare row_parent_id int;
declare cnt int default 0;
declare i int default 0;
declare getcategory cursor for select a.id,b.org_id from teacher_timeline as a left join teacher_class as b on a.class_id = b.id;
select count(*) into cnt from teacher_timeline;
open getcategory;
repeat
set i:=i+1;
fetch getcategory into row_cat_id,row_cat_id_org;
update teacher_timeline set org_id = row_cat_id_org where id=row_cat_id;
until i>=cnt end repeat;
close getcategory;
end$
call my_procedure()$