如果(stat=__i_)这句话中的奇数引号似乎是问题-更改为单引号,过程正常。
如有借阅人,可直接删除表格,罚款;
创建表借用人(
Rollno int(11),
姓名varchar(30)
出炉日期,
书籍名称varchar(20)
状态变量(2)
;
插入借款人价值
(1,'A'、'2018-09-10'、'BA'、'I'),
(2,'b'、'2018-09-10'、'b b'、'i'),
(3,'C'、'2018-09-01'、'CC'、'R'),
(4,'d'、'2018-08-01'、'd d'、'i'),
(5,'E'、'2018-09-21'、'EE'、'I'),
(6,'F'、'2018-09-18'、'FF'、'I');
create table fine
( rollno int(11),
days int(11),
amt int(11));
drop procedure if exists proce;
Delimiter //
Create procedure proce(in roll int, in bname varchar(20))
Begin
Declare notfound int default 0;
Declare rno int default 0;
Declare name varchar(20);
Declare doi date;
Declare nob varchar(20);
Declare stat varchar(20);
Declare diff int default 0;
Declare fine int default 0;
Declare cursor_name cursor for select rollno, name, dataofissue, nameofbook, status from borrower;
Declare continue handler for NOT FOUND set notfound=1;
Open cursor_name;
loop_1 : LOOP
fetch cursor_name into rno, name, doi, nob, stat ;
If notfound=1 then
leave loop_1;
end if;
If(rno=roll and nob=bname) then
Select datediff(curdate(),doi) as DAYS into diff;
if(stat='I') then
if(diff >=15 and diff <=30 ) then
set fine=( diff-15 )*5;
elseif( diff > 30 ) then
set fine=(diff-30)*50 + 15*5;
end if;
insert into fine values(rno,diff,fine);
update borrower set status='D' where rollno=rno;
end if;
End if;
End LOOP loop_1;
Close cursor_name;
End //
call proce(1,'Ba');
select * from fine;
+--------+------+------+
| rollno | days | amt |
+--------+------+------+
| 1 | 42 | 675 |
+--------+------+------+
1 row in set (0.00 sec)
我还将检查列、声明的变量和参数是否具有相同的名称和反勾号状态。