[@more@] create table heyf_6 (empid int , deptid int ); insert into heyf_6 values (1,20),(2,30),(5,20),(4,50),(6,20);
--按DEPTID从小到大打印各个部分里的EMPID
DROP PROCEDURE IF EXISTS proc_empid; DELIMITER //
CREATE PROCEDURE proc_empid() BEGIN declare done int default 0; declare v_dept int ; declare cur_dept cursor For select distinct deptid from heyf_6 order by deptid ; DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
end if ; select '------------',@dept,v_emp ; end loop cur_loop; close cur_emp; end; end loop cursor_loop ; close cur_dept; END ;// DELIMITER ;