wangwei пре 7 година
родитељ
комит
7175c91993
1 измењених фајлова са 11 додато и 5 уклоњено
  1. 11 5
      sql/考生导入-存储过程.sql

+ 11 - 5
sql/考生导入-存储过程.sql

@@ -1,6 +1,7 @@
 CREATE DEFINER=`root`@`%` PROCEDURE `import_exam_students`(IN `batch_id` bigint)
 BEGIN
-	DECLARE done INT DEFAULT FALSE;
+	declare total BIGINT(20);
+	declare count BIGINT(20);
 	declare id BIGINT(20);
 	declare course_id_temp BIGINT(20);
 	declare course_id BIGINT(20);
@@ -17,15 +18,16 @@ BEGIN
 	from ec_e_exam_student_tmp t 
 	where t.batch_id= batch_id;
 	
-	DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
+  set count = 0;
+	select count(1) into total 	from ec_e_exam_student_tmp t 	where t.batch_id= batch_id;
+	
 	open cursor_temp;
 	
 	read_loop: LOOP
+		set count = count+1;
 		FETCH cursor_temp INTO id,course_id,org_id,course_code,student_code,identity_number,org_code,root_org_id;
 		
-		IF done THEN
-			LEAVE read_loop;
-		END IF;
+    SELECT		id,course_id,org_id,course_code,student_code,identity_number,org_code,root_org_id;
 		
 		IF course_id is null THEN
 			SELECT x.id into course_id_temp from ecs_core_course x where x.code= course_code and x.org_id=root_org_id;
@@ -45,6 +47,10 @@ BEGIN
 		
 		commit;
 		
+		IF total = count THEN
+			LEAVE read_loop;
+		END IF;
+		
 	END LOOP;
  	
     close cursor_temp;