BEGIN
#遍历占领野地表还原军队
#update armforce set number=num where troopsid=(select id from troops where isfrist=1 and cityid=cityid)
DECLARE tId DECIMAL(21,0) default -1;#occupyWild表的TroopsId
DECLARE cid DECIMAL(21,0) default -1;#occupyWild表的CityId
DECLARE temp_tId DECIMAL(21,0) default -1;#occupyWild表的TroopsId
DECLARE temp_cid DECIMAL(21,0) default -1;#occupyWild表的CityId
DECLARE tId2 DECIMAL(21,0) default -1;#troops表的TroopsId
DECLARE num0 int default 0;
DECLARE num1 int default 0;
DECLARE num2 int default 0;
DECLARE num3 int default 0;
DECLARE curl CURSOR FOR SELECT TroopsId,CityId FROM occupyWild order by TroopsId ASC;
DECLARE CONTINUE HANDLER FOR SQLSTATE '' SET tId = -1;
OPEN curl;
FETCH curl INTO tId,cid;
WHILE(tId<>-1) DO
#说明:游标变量使用一次以后就会被清除
#************************ 逻辑 START ************************
set tId2=-1,temp_tId=-1,temp_cid=-1,num0=0,num1=0,num2=0,num3=0;
set temp_tId=tId;
set temp_cid=cid;
select id into tId2 from Troops where isFrist=1 and CityId=temp_cid limit 1;#正常情况下只有一条数据
select number into num0 from Armforce where TroopsId=temp_tId and ArmType=0;
select number into num1 from Armforce where TroopsId=temp_tId and ArmType=1;
select number into num2 from Armforce where TroopsId=temp_tId and ArmType=2;
select number into num3 from Armforce where TroopsId=temp_tId and ArmType=3;
update Armforce set Number=Number+num0 where TroopsId=tId2 and ArmType=0;#退回军队
delete from Armforce where TroopsId=temp_tId and ArmType=0;#删除军队
update Armforce set Number=Number+num1 where TroopsId=tId2 and ArmType=1;
delete from Armforce where TroopsId=temp_tId and ArmType=1;
update Armforce set Number=Number+num2 where TroopsId=tId2 and ArmType=2;
delete from Armforce where TroopsId=temp_tId and ArmType=2;
update Armforce set Number=Number+num3 where TroopsId=tId2 and ArmType=3;
delete from Armforce where TroopsId=temp_tId and ArmType=3; #************************ 逻辑 END ************************ FETCH curl into tId,cid;
END WHILE;
CLOSE curl; END

mysql中游标的使用的更多相关文章

  1. mysql中游标的使用案例详解(学习笔记)

    1.游标是啥玩意?简单的说:游标(cursor)就是游动的标识,啥意思呢,通俗的这么说,一条sql取出对应n条结果资源的接口/句柄,就是游标,沿着游标可以一次取出一行.我给大家准备一张图: 2.怎么使 ...

  2. mysql中游标的使用案例详解(学习笔记)(转)

    1.游标是啥玩意?简单的说:游标(cursor)就是游动的标识,啥意思呢,通俗的这么说,一条sql取出对应n条结果资源的接口/句柄,就是游标,沿着游标可以一次取出一行.我给大家准备一张图: 2.怎么使 ...

  3. Oracle存储过程中游标的简单使用

    存储过程中查询语句如何返回多行结果? 我们知道,如果存储过程中查询语句有多行结果输出,会报错:ORA-01422: exact fetch returns more than requested nu ...

  4. MySQL/MariaDB中游标的使用

    本文目录:1.游标说明2.使用游标3.游标使用示例 1.游标说明 游标,有些地方也称为光标.它的作用是在一个结果集中逐条逐条地获取记录行并操作它们. 例如: 其中select是游标所操作的结果集,游标 ...

  5. SQL Server中游标的使用

    举个栗子: -- 临时变量 DECLARE @Id UNIQUEIDENTIFIER -- 声明游标名 DECLARE cursor_name CURSOR FOR SELECT ID from CO ...

  6. SQL中游标的使用

    一般情况下,我们用SELECT这些查询语句时,都是针对的一行记录而言,如果要在查询分析器中对多行记录(即记录集)进行读取操作时,则需要使用到游标或WHILE等循环 游标的类型:  1.静态游标(不检测 ...

  7. plsql编程中游标的使用

    游标(Cursor):用来查询数据库,获取记录集合(结果集)的指针,可以让开发者一次访问一行结果集,在每条结果集上作操作. oracle中显示使用游标一般要包含以下5个步骤: 声明一些变量以便存储从游 ...

  8. SQL中游标的使用--遍历数据逐行更新或删除:相当于for循环

    --------------------------------------例子1 单纯的游标-------------------------------- create TABLE Table1 ...

  9. SQL中游标的用法

    游标:是用来对表从上下每行循环取值,将值连接成为字符串.例子:对 pubs 数据库的dbo.titles 表.1.取得表中的总价格:select sum(price) from dbo.titles2 ...

随机推荐

  1. x86-64_register_and_function_frame.html

    http://www.searchtb.com/2013/03/x86-64_register_and_function_frame.html

  2. 怎么保护PDF文档和扫描文件里的机密信息

    从事商务工作的人,必然要处理带有机密信息的文档,需要分享这些文档的时候,如何谨慎小心地对待那些机密信息,说到底还是取决于自己.分享文档的目的不同,对文档的保护类型和级别也不一样.例如,只有授权的读者才 ...

  3. linux包之bash之内置命令ulimit

    概述 [root@localhost ~]# rpm -qa|grep bashbash-4.1.2-15.el6_4.x86_64 linux limits.conf 配置 limits.conf ...

  4. 【转】[NOIP2003普及组]麦森数

    来源:http://vivid.name/tech/mason.html 不得不纪念一下这道题,因为我今天一整天的时间都花到这道题上了.因为这道题,我学会了快速幂,学会了高精度乘高精度,学会了静态查错 ...

  5. 第一篇帖子,就弄个JS动态公告浏览吧,直接上代码

    .scroll{    margin-left:45px;    margin-top:-150px;    height:100px;    width:300px;} <script lan ...

  6. 计算机中丢失 msvcr110.dll 怎么办

    笔者在一次运行 php.exe 时,运到“无法启动此程序,因为计算机中丢失 MSVCR110.dll.尝试重新安装该程序以解决此问题.”的提示,当时很无语,因为系统是刚刚安装好的,而且是最新版本的. ...

  7. jsoncpp 生成 json 字符串

    Json::Value root; Json::Value arrayObj; Json::Value item; for (int i=0; i<10; i++) { item["k ...

  8. 转载:scikit-learn学习之SVM算法

    转载,http://blog.csdn.net/gamer_gyt 目录(?)[+] ========================================================= ...

  9. net cookie操作

    写入方法: HttpCookie cookie = new HttpCookie("id"); cookie.Value=cookieValue; cookie.Expires = ...

  10. css禁用鼠标点击事件

    css禁用鼠标点击事件 .disabled { pointer-events: none; } <div class="main-container disabled"> ...