MySql cross-database stored procedure operation note bitsCN.com
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 Province, sm_len, data_coding, province, src_addr, province, service_type, sm_content, link_id, region, 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 values (values, sm_len, data_coding, to_sp_id, src_addr, values, service_type, sm_content, link_id, values, 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
Author: Vionsam
BitsCN.com