mysql 存储过程 同步数据_MySQL存储过程跨数据库操作同步数据

BEGIN

DECLARE deliverstatus,smlen,datacoding,total int;

DECLARE tsid,srcaddr,destaddr,servicetype,smcontent,linkid,sequenceno,recvtime,state,resulttime,extcode,applicationid varchar(50) ;

set total = 0;

while total < 20 do

set tsid='';

select deliver_status,sm_len,data_coding,to_sp_id,src_addr,dest_addr,service_type,sm_content,link_id,sequence_no,recv_time,state,result_time,extcode_,applicationid_ into deliverstatus,smlen,datacoding,tsid,srcaddr,destaddr,servicetype,smcontent,linkid,sequenceno,recvtime,state,resulttime,extcode,applicationid

from tlc_to_sp where applicationid_ = 'sms_db' limit 0,1;

if tsid <> '' then

if resulttime <> '' and recvtime <> '' then

insert into kingterdb.sms_inbox(MASSMSID,SOURCEADDR,RECEIVETIME,MESSAGECONTENT,REQUESTTIME,extcode,applicationid) values(tsid,srcaddr,resulttime,smcontent,recvtime,extcode,applicationid);

elseif resulttime = '' then

insert into kingterdb.sms_inbox(MASSMSID,SOURCEADDR,RECEIVETIME,MESSAGECONTENT,REQUESTTIME,extcode,applicationid) values(tsid,srcaddr,now(),smcontent,recvtime,extcode,applicationid);

elseif recvtime = '' then

insert into kingterdb.sms_inbox(MASSMSID,SOURCEADDR,RECEIVETIME,MESSAGECONTENT,REQUESTTIME,extcode,applicationid) values(tsid,srcaddr,resulttime,smcontent,now(),extcode,applicationid);

else

insert into kingterdb.sms_inbox(MASSMSID,SOURCEADDR,RECEIVETIME,MESSAGECONTENT,REQUESTTIME,extcode,applicationid) values(tsid,srcaddr,now(),smcontent,now(),extcode,applicationid);

end if;

insert into tlc_to_sp_his(deliver_status,sm_len,data_coding,to_sp_id,src_addr,dest_addr,service_type,sm_content,link_id,sequence_no,recv_time,state,result_time,extcode_,applicationid_) values(deliverstatus,smlen,datacoding,tsid,srcaddr,destaddr,servicetype,smcontent,linkid,sequenceno,recvtime,state,resulttime,extcode,applicationid);

end if;

delete from tlc_to_sp where to_sp_id in(select to_sp_id from tlc_to_sp_his where applicationid_ = 'sms_db');

set total = total + 1;

end while;

END此存储过程在newppp数据库中插入数据到kingterdb数据库的表中。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值