create PROCEDURE update_ampm()
begin
DECLARE aid int(11);
DECLARE sect VARCHAR(80);
DECLARE star VARCHAR(80);
DECLARE ene VARCHAR(80);
DECLARE times VARCHAR(80);
DECLARE d int default 0;
DECLARE cursor_ampm CURSOR FOR SELECT id,timeStr from t_ampm;
DECLARE CONTINUE HANDLER for not found set d=1;
open cursor_ampm;
FETCH cursor_ampm into aid, times;
while d<>1 do
SET sect = SUBSTRING_INDEX(times,' ',1);
SET star= SUBSTRING_INDEX(SUBSTRING_INDEX(times,' ',-1),'-' ,1);
SET ene = SUBSTRING_INDEX(SUBSTRING_INDEX(times,' ',-1),'-' ,-1);
UPDATE t_ampm SET sectionNum = sect,startTime=star,endTime=ene WHERE id=aid;io
FETCH cursor_ampm into aid,times;
end while;
close cursor_ampm;date