mysql 存储过程 使用游标demo

直接上代码,使用游标 repeat循环:

--   游标 repeat循环
create procedure test()
begin
DECLARE ct VARCHAR(32);
declare cnt int default 0;
declare i int default 0;
declare done int default 0;
DECLARE citys CURSOR FOR select replace(name,"城区","")as city from area where level ='city';
declare continue handler for not found set done = 1;
select count(name) into cnt  from  area  where level ='city';

OPEN citys;    
    repeat
        FETCH citys into ct;
           if done != 1 then
              update  deliver  set city = (case  when INSTR(address, ct) then ct end);
                            COMMIT;
           end if;
        until done = 1
    end repeat;

CLOSE citys;
end;
 

你可能感兴趣的:(mysql,数据库,java,游标,存储过程)