mysql 存储过程 循环
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 |
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。