MySQL库数据库存储过程

时间:2012-04-03 13:57:39

标签: mysql database phpmyadmin

我有一个存储过程,应该从(虚构的)库数据库借书,该过程应该检查该书是否可用,然后用户没有超过其限制,然后减少数量在书表中可用于所选书籍的副本(我知道,这不是我将如何布置数据库)并创建新的贷款,然后返回一个字符串以告知程序是否已经执行而没有任何问题。这是程序:

delimiter $$
create procedure BorrowBook(in theBookID int, in theUserID int)
begin
declare lim int;
declare num int;
declare loanNumber int;
declare copyNumber int;
set lim = (select Readers.Limit from Readers where Readers.id = theUserID);
set num = (select Count(*) from Loans where Loans.UserID = theUserID);
set loanNumber = (select Count(*) from Loans) + 1;
set copyNumber = (select NumberAvailable from Book where Book.id = theBookID);
if(copyNumber > 0)
then
if(num<lim)
then
insert into Loans values(loanNumber, theBookID, theUserID, curDate(), 0);
commit;
update Book set Book.NumberAvailable = Book.NumberAvailable - 1 where Book.id = theBookID;
select 'Succesful Update';
else
rollback;
select 'Borrow limit reached';
end if;
else
rollback;
select 'No copies available';
end if;
end $$

但如果我这样称呼它:

call BorrowBook(2,2);

它出现了错误

#1312 - PROCEDURE reddurrant_com.BorrowBook can't return a result set in the given context

请有人让我知道它为什么不起作用?干杯

0 个答案:

没有答案