1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
网摘<br>DELIMITER $$ CREATE DEFINER=`root`@`%` PROCEDURE
`sp_pament_TrainFee`()
BEGIN /*局部变量的定义 declare*/ declare strYear int ;
declare strEnrollID int ;
declare feesum int ;
declare stop int default
0;
declare
cur cursor
for (
select
year ,EnrollID , sum (Fee) from
trainmanage where
ReturnStatus !=1 group
by Year ,EnrollID );
/*这把 游标 异常后 捕捉
* 并设置 循环使用 变量 stop 为 null 跳出循环。
*/ declare
CONTINUE HANDLER FOR
SQLSTATE ‘02000‘
SET stop = null ;
/*开游标*/ OPEN cur;
/*游标向下走一步,将查询出来的值付给定义的变量*/ FETCH
cur INTO strYear,strEnrollID,feesum;
WHILE ( stop is
not null ) DO
update
payment set
ExpectTrain=feesum where
EnrollID = strEnrollID and
right (ID,2) = right (strYear,2) ;
FETCH
cur INTO strYear,strEnrollID,feesum;
END
WHILE;
/*游标向下走一步*/ CLOSE cur;
END |
相关文章
- 07-21Sql存储过程
- 07-21SQL存储过程基于字段名传入的字符串拼接.
- 07-21SQL 存储过程 传入数组参数
- 07-21sql 解析字符串添加到临时表中 sql存储过程in 参数输入
- 07-21SqlServer_存储过程
- 07-21sqlserver存储过程创建和java调用
- 07-21存储过程 100w提交
- 07-21SQL分页存储过程(不支持多表联合查询,不支持多字段排序)
- 07-21顺序循环队列和链式存储队列(带头结点和不带头结点)
- 07-21存储过程授权给子用户