The company's time stamp certificate business, to the release process intermediate data processing needs to use the stored procedure. Make a short record of this to avoid forgetting.
DROP procedurerecord_timestamp_deal; # #创建存储过程Create procedurerecord_timestamp_deal ()beginDeclareTslogidvarchar( -);DeclareDoneint default 0;# Declareexistence Boolean; # #从时间戳记录表中获取ID存入游标DeclareCurcursor for SelectId fromtime_stamp_log;# #异常处理Declare ContinueHandler forSQLState'02000' SetDone= 1;Opencur; # #取出游标值至变量中Fetch Next fromCur intoTslogid; Repeatif notDone Then#查询时间戳待记录id是否在时间戳待存证表if(Select * fromOsv_timestamp_evi_preparewhereTimestampid=Tslogid) is not NULL Then# #不存在的记录写入待存证表Insert intoOsv_timestamp_evi_prepare (Timestampid,createtime)Values(Tslogid,now ()); End if; End if; # #重新抓取数据进入循环Fetch Next fromCur intotslogid;# #结束循环until DoneEndrepeat;# #关闭游标Closecur;End; call Record_timestamp_deal ();
MySQL stored procedure (proceduce) query results of one table insert another table