>  기사  >  백엔드 개발  >  这段mysql存储过程是否有错误?

这段mysql存储过程是否有错误?

WBOY
WBOY원래의
2016-06-06 20:07:46964검색

<code>DELIMITER //
create 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 c1 cursor for select orderid,amount from orders;
    declare continue handler for SQLSTATE '02000' set done = 1;
    
    
    open c1;
    repeat 
        fetch c1 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 c1;
    set largest_id = l_id;
END
//
DELIMITER ;</code>

代码如上,在navicat报错
这段mysql存储过程是否有错误?

回复内容:

<code>DELIMITER //
create 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 c1 cursor for select orderid,amount from orders;
    declare continue handler for SQLSTATE '02000' set done = 1;
    
    
    open c1;
    repeat 
        fetch c1 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 c1;
    set largest_id = l_id;
END
//
DELIMITER ;</code>

代码如上,在navicat报错
这段mysql存储过程是否有错误?

已解决,是代码有遗漏,末尾缺少斜杠

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.