delimiter $$
dropprocedureifexists create_data_for_test2;createprocedure create_data_for_test2(in num int,out total int)begindeclare count intdefault0;declare batch_num intdefault0;
dd:loopSTARTTRANSACTION;--手動提交事務,提高效率
batch:loopinsertinto test2(b,c,d,e)values(round(rand()*10),round(rand()*10),round(rand()*10),round(rand()*count));set count=count+1;set batch_num:=batch_num+1;if count>=num thenleave dd;endif;if batch_num>=10thencommit;set batch_num=0;leave batch;endif;endloop batch;endloop dd;commit;selectcount(*)into total from test2;end;$$
delimiter;showprocedurestatus;dropprocedure create_data;
函數
delimiter $$
createfunction get_b_by_a(a1 int)returnsintbegindeclare b_test2 intdefault0;select b into b_test2 from test2 where a=a1;return b_test2;end$$
delimiter;showfunctionstatus\G;