CREATE PROCEDURE `relation_update`(in ePID varchar(100),in deptid int)
BEGIN
DECLARE tui varchar(100);
declare ct int;
declare i int;
DECLARE cur1 CURSOR FOR select dp.id from department dp where dp.ePID=ePID;
select count(1) into ct from department dp where dp.ePID=ePID;
update department fs set fs.departmentID=deptid where fs.ePID=ePID;
OPEN cur1;
set i=0;
---- 设置深度1万的深度
SET @@max_sp_recursion_depth = 10000;
---- 如果需要修改的数据大于i,就继续调用自己修改
while i<ct do
----- 将需要修改的值传递到变量tui
FETCH cur1 INTO tui;
------ 自己调用自己
call relation_update(tui,deptid);
SET i=i+1;
end while;
close cur1;
END