公司的時間戳存證業務,對發版過程中間數據處理需要用到存儲過程。對此做一個簡短記錄,以免遺忘。
DROP procedure record_timestamp_deal ; ##創建存儲過程 create procedure record_timestamp_deal() begin declare tslogId varchar(50); declare done int default 0; # declare existence boolean ; ##從時間戳記錄表中獲取ID存入游標 declare cur cursor for select id from time_stamp_log; ##異常處理 declare continue handler for sqlstate '02000' set done = 1; open cur; ##取出游標值至變量中 fetch next from cur into tslogId; repeat if not done then #查詢時間戳待記錄id是否在時間戳待存證表 if (select * from osv_timestamp_evi_prepare where timestampId = tslogId) is not null then ##不存在的記錄寫入待存證表 insert into osv_timestamp_evi_prepare(timestampId,createTime) values(tslogId,now()); end if; end if; ##重新抓取數據進入循環 fetch next from cur into tslogId; ##結束循環 until done end repeat; ##關閉游標 close cur; end ; call record_timestamp_deal();