# define variables
Declare check_id int.
Declare check_year int.
Declare check_month int.
Declare check_day int.
Declare check_In time;
Declare check_Out time;
Declare student_Id int.
# set the traverse the end condition
Declare flag int the default 0;
# define cursor
Declare check_info cursor for
Select * from t_check where student_id=studentId and month=select_month;
Declare the continue handler for the not found set flag=1;
# to open the cursor
The open check_info;
# set loop out point
Read_loop: Loop
# traversal cursor, values
The fetch check_info into check_id, check_year check_month, check_day, check_In, check_Out, student_Id;
Countless according to # can traverse is
exit cycleIf flag=1 then
Leave read_loop;
end if;
# your practice
Insert into t_check_test
Values (check_id check_year, check_month check_day, check_In, check_Out, student_Id);
# end of cycle
END Loop;
# close the cursor
The close check_info;
# transaction commit
commit;
End
Table t_check:

T_check table structure:

Operation success:


But the new table data:

The new table structure:

CodePudding user response:
You see from the original list according to pass the values of the parameters, can find out the result?