mysql 預存程序(proceduce)查詢一個表的結果插入另外一個表

來源:互聯網
上載者:User

標籤: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)查詢一個表的結果插入另外一個表

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.