谁能帮我修改一下mysql存储过程的代码

delimiter $$
drop procedure if exists p1;
create procedure p1()
begin
declareE a char(16);
declare cur cursor for select * from `test`;
declare done int default false;
declare continue handler for not found set done = true;
open cur;
read_loop: loop
fetch cur into @a;
if done then
leave read_loop;
end if;
insert into part (`title`) values ('233');
end loop;
close cur;
end;
$$

他给我报[Err] 1337 - Variable or condition declaration after cursor or handler declaration
----------------------------------------------------------------------------------------------------------------------------
按照网上的说法 我把 declare continue handler for not found set done = true; 放在定义游标的前面,但是还是报错。谁能够帮我调一下代码啊?我是在找不到哪里错了。
当前问题共有如下(2)个解决方案
  • 匿名用户
    匿名用户
    1)
    declare a char(16);
    declare done boolean default false;
    declare cur cursor for select * from `test`;
    declare continue handler for not found set done = true;

    2)
    fetch cur into a;
  • edit98
    edit98
    delimiter $$
    drop procedure if exists p1; --这里顺序调换一下
    ----------------------------------------------------
    declareE a char(16);
    declare done int default 0;
    declare cur cursor for select * from `test`;
    declare continue handler for not found set done = 1; --这里我建议是true改成1
    open cur;
    --这里一个错误,是声名错误,要先声名变量,然后游标,然后才是handler
    -------------------------------------------------------------------------------------

    fetch cur into @a; --fetch cur into 列1,列2
    --这里最好指明到那个某个列或者多个列。。而不是把这样整个表拿出来“select * from ”

    -------------------------------------------------------------------------------------

    if done then --这里应该是 if not done then 到结束后要设置回0。
上一篇:php 使用面相对象连接mysqli的方法是什么?就是php5.5版本的,最好给个例子了。 相关函
下一篇:mysql 1452外键错误