1

我正在编写一个程序,它将通过一个表并收集所有前 10 个结果。我正在使用游标然后获取结果。我对如何打印结果有点困惑。我使用了一个 select 语句来获得这些结果,但我被告知有一个错误。

任何帮助将不胜感激。谢谢。

create procedure plant_list()
begin
declare v_plant_id integer(5);
declare v_common_name varchar(30);
declare v_scientific_name varchar(20);


declare finished boolean default false;

declare cur_top_ten cursor for
    select P.plant_id, common_name, concat(genus, ' ', species)
    from plants P
        join plant_taxonomy PT on P.plant_id = PT.plant_id
    order by list_price desc
    limit 10
    ;

declare continue handler for not found set finished = true;

open cur_top_ten;
curloop: loop
    fetch cur_top_ten into v_plant_id, v_common_name, v_scientific_name;
    if finished then
        close cur_top_ten;
        set finished = false;
        leave curloop;
    end if

    select v_plant_id, v_common_name, v_scientific_name;


end loop curloop;

end;
#
4

1 回答 1

1

if 结尾后缺少一个分号!

  if finished then
    close cur_top_ten;
    set finished = false;
    leave curloop;
  end if;
于 2012-09-30T07:35:23.103 回答