小编SRG*_*SRG的帖子

如何在mysql中使用结束循环进行游标循环

以下代码用于从名为employee7的表中查找前五名最高薪员工,并使用mysql中的游标将详细信息添加到另一个名为temp的表中,但出现错误

你的mysql语法有错误,检查与mysql服务器版本相对应的手册,以获取使用near'loopcursorloop;的正确语法。关闭c7;结尾; 在第 17 行

DELIMITER //
create procedure cursordemo()
begin 
    declare eno int(8);
    declare ename varchar(15);
    declare esal int(10);
    declare c7 cursor for select empno,empnm,empsal from employee7 order by empsal desc;
    open c7;
    cursorloop:loop
    fetch c7 into eno,ename,esal;
    if c7.rowcount>5 then  
        leave cursorloop;
    insert into temp values (esal,eno,ename);
    end loop cursorloop;
    close c7;
    end //
delimiter ;
Run Code Online (Sandbox Code Playgroud)

mysql database

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

database ×1

mysql ×1