MySQL stored procedure (proceduce) query results of one table insert another table

Source: Internet
Author: User
Tags one table

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.