我正在尝试在Library数据库上创建一个存储过程,主要用于练习。
但这让我感到困惑。我正在使用此查询来创建过程,它说它正在工作,但是当我调用该过程时,它表示该过程不存在。注意:我在不在本地主机上的Web数据库上使用phpmyadmin。
delimiter $$
create procedure BorrowBook(in theBookID, in theUserID)
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)
if(num<lim)
then
--Add a Loan to the Loans Table
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;
delimiter ;
答案 0 :(得分:2)
您错过了$$
之后的end
:
delimiter $$
...
end; $$ <-- add $$ here
delimiter ;
答案 1 :(得分:0)
不应该是
end; $$
delimiter ;
而不是
end;
delimiter ;