mysql存储过程的游标和控制结构

WBOY
發布: 2016-06-07 14:56:45
原創
1278 人瀏覽過

通过该段代码理解mysql存储过程的游标和控制结构 MySQL DELIMITER $$DROP PROCEDURE IF EXISTS `books`.`largest_order`$$CREATE DEFINER=`root`@`192.168.18.248` PROCEDURE `largest_order`(out largest_id int)BEGIN declare this_id int; declare this_am

通过该段代码理解mysql存储过程的游标和控制结构 MySQL
DELIMITER $$

DROP PROCEDURE IF EXISTS `books`.`largest_order`$$

CREATE DEFINER=`root`@`192.168.18.248` PROCEDURE `largest_order`(out largest_id int)
BEGIN
 declare this_id int;
 declare this_amount float;
 declare l_amount float default 0.0;
 declare l_id int;
 declare done int default 0;
 declare cl cursor for select orderid,amount from orders;
 declare continue handler for sqlstate '02000' set done =1;
 open cl;
 repeat
   fetch cl into this_id,this_amount;
   if not done then
     if this_amount > l_amount then
        set l_amount = this_amount;
        set l_id = this_id;
      end if;
    end if;
 until done end repeat;
 close cl;
 set largest_id = l_id;
END$$

DELIMITER ;
登入後複製
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板