BEGIN#遍历占领野地表还原军队 #UpdateArmforceSet Number=NumwhereTroopsid=(SelectId fromTroopswhereIsfrist=1 andCityid=Cityid)DECLARETIdDECIMAL( +,0)default -1; #occupyWild表的TroopsIdDECLARECidDECIMAL( +,0)default -1; #occupyWild表的CityIdDECLARETemp_tidDECIMAL( +,0)default -1; #occupyWild表的TroopsIdDECLARETemp_cidDECIMAL( +,0)default -1; #occupyWild表的CityIdDECLARETId2DECIMAL( +,0)default -1; #troops表的TroopsIdDECLARENum0int default 0; DECLARENum1int default 0; DECLARENum2int default 0; DECLARENum3int default 0; DECLARECurlCURSOR for SELECTTroopsid,cityid fromOccupywildOrder byTroopsidASC; DECLARE CONTINUEHANDLER forSQLSTATE'02000' SETTId= -1; OPENCurl; FETCHCurl intoTid,cid; while(tId<>-1do #说明: The cursor variable is used once and then is cleared #************************Logic START************************ SetTId2=-1, Temp_tid=-1, Temp_cid=-1, NUM0=0, NUM1=0, num2=0, num3=0; SetTemp_tid=tId; SetTemp_cid=CID; SelectId intoTId2 fromTroopswhereIsfrist=1 andCityid=Temp_cid limit1; #正常情况下只有一条数据Select Number intoNum0 fromArmforcewhereTroopsid=Temp_tid andArmtype=0; Select Number intoNum1 fromArmforcewhereTroopsid=Temp_tid andArmtype=1; Select Number intoNum2 fromArmforcewhereTroopsid=Temp_tid andArmtype=2; Select Number intoNum3 fromArmforcewhereTroopsid=Temp_tid andArmtype=3; UpdateArmforceSet Number= Number+Num0whereTroopsid=TId2 andArmtype=0; #退回军队Delete fromArmforcewhereTroopsid=Temp_tid andArmtype=0; #删除军队UpdateArmforceSet Number= Number+Num1whereTroopsid=TId2 andArmtype=1; Delete fromArmforcewhereTroopsid=Temp_tid andArmtype=1; UpdateArmforceSet Number= Number+Num2whereTroopsid=TId2 andArmtype=2; Delete fromArmforcewhereTroopsid=Temp_tid andArmtype=2; UpdateArmforceSet Number= Number+Num3whereTroopsid=TId2 andArmtype=3; Delete fromArmforcewhereTroopsid=Temp_tid andArmtype=3; #************************LogicEND ************************ FETCHCurl intoTid,cid; END while; CLOSECurl; END
Use of the MySQL midstream target