源代码:
-> create procedure GetMaxExpensiveISBN(out BookId int)
-> begin
->
-> declare this_id int;
-> declare this_price float;
-> declare one_id int;
-> declare one_price float default 0.0;
->
-> declare done int default 0;
-> declare c1 cursor for select ISBN,Price from books;
-> declare continue handler for sqlstate '02000' set done = 1;
->
-> open c1;
-> repeat
-> fetch c1 into this_id,this_price;
->
-> if not done then
-> if this_price > one_price then
-> set one_price = this_price;
-> set one_id = this_id;
-> end if;
-> end if;
->
-> until done end repeat;
->
-> close c1;
->
-> set BookId = one_id;
->
-> end
特别注意: cursor 要在 handler 前边定义!