欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2024-01-08 18:57:22
...
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 ;

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

回复内容:

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 ;

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

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

相关标签: php mysql

上一篇:

下一篇: