mysq 游标哪里错了?感觉没错

delimiter $
create function youbiao()
begin

declare a varchar(20);
declare flag int default false;
declare d int;
# 声明一个游标

declare mycursor cursor for select age,dogname from dog;# 游标一定要在变量后申明

声明一个游标的终止条件

declare continue handler for not found set flag=true; # set flag是一个变量用作判断
open mycursor; #打开mycursor这个游标
while !flag do
fetch mycursor into d,a ;
select d,a;
end while;
close mycursor;
end $
delimiter ;

     You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'begin 

2个回答

delimiter $
create function youbiao()
begin
declare a varchar(20);
declare flag int default false;
declare d int;
# 声明一个游标
declare mycursor cursor for select age,dogname from dog;# 游标一定要在变量后申明

声明一个游标的终止条件

declare continue handler for not found set flag=true; # set flag是一个变量用作判断
open mycursor; #打开mycursor这个游标
while !flag do
fetch mycursor into d,a ;
select d,a;
end while;
close mycursor;
end $
delimiter ;

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'begin

delimiter $
create procedure youbiao()
begin
declare a varchar(20);
declare flag int default false;
declare d int;
# 声明一个游标
declare mycursor cursor for select age,dogname from dog;# 游标一定要在变量后申明

声明一个游标的终止条件

declare continue handler for not found set flag = true; # set flag是一个变量用作判断
open mycursor; #打开mycursor这个游标
while flag do
fetch mycursor into d,a ;
select d,a;
end while;
close mycursor;
end $
delimiter ;

还是不行
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐