標籤:weight span sel 業務 抓取 handle pid handler close
公司的時間戳記存證業務,對發版過程中間資料處理需要用到預存程序。對此做一個簡短記錄,以免遺忘。
DROP procedure record_timestamp_deal ;##建立預存程序create procedure record_timestamp_deal()begindeclare 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();
mysql 預存程序(proceduce)查詢一個表的結果插入另外一個表