存储过程 游标

begin
declare l_judge_id int default 0;
declare l_cnt int default 0;
declare done int default 0;
declare l_cursor cursor for select judge_id from judge_court_dict ORDER BY  judge_id asc;
declare continue handler FOR SQLSTATE '02000' SET done = 1;
open l_cursor;
repeat
  
fetch l_cursor into l_judge_id;
   if not done then
      select count(1) as cnt into l_cnt from judge_case where judge_id = l_judge_id ; 
      update judge_court_dict set cnt=l_cnt where judge_id=l_judge_id;

   end if;
until done end repeat;
close l_cursor;
END

 

posted on 2017-11-27 13:46  ziyi_ang  阅读(90)  评论(0编辑  收藏  举报

导航