mysql 存储过程(proceduce)查询一个表的结果插入另外一个表

公司的时间戳存证业务,对发版过程中间数据处理需要用到存储过程。对此做一个简短记录,以免遗忘。

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();

 

转载于:https://www.cnblogs.com/HEWU10/p/6795391.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值