• Cursor fetch語句用來獲取游標指定數據集的下一行數據並將各個字段值賦予后面的變量
• 數據集中的字段需要和INTO語句中定義的變量一一對應
• 數據集中的數據都fetch完之后,則返回NOT FOUND
delimiter // CREATE PROCEDURE curdemo2() BEGIN DECLARE done INT DEFAULT true; DECLARE v_name varchar(64); DECLARE v_id int; DECLARE v_dept_id int; DECLARE cur1 CURSOR FOR SELECT id,name,dept_id FROM teacher; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = false; open cur1; fetch cur1 into v_id,v_name,v_dept_id; while done do select v_id,v_name,v_dept_id; select 'row-----------' abc; fetch cur1 into v_id,v_name,v_dept_id; end while; close cur1; end; // delimiter ;
