drop procedure if exists cursorproc // create procedure cursorproc(OUT p_out DECIMAL(5,2)) begin declare l_loop_end INT default 0; declare l_salary, l_total DECIMAL(5,2); declare cur_1 cursor for select salary from emps; declare continue handler for sqlstate '02000' set l_loop_end = 1; open cur_1; set l_total = 0; repeat fetch cur_1 into l_salary; if not l_loop_end then set l_total = l_total + l_salary; end if; until l_loop_end end repeat; close cur_1; set p_out = l_total; end; //