错误代码1172 - 结果由多行组成

时间:2017-01-02 21:43:40

标签: mysql

您好我很难使用此存储过程。我得到错误:结果由多行组成。

这是我的存储过程:

    delimiter //
    create procedure cars1 (in v_tara1 int, in v_an year, in v_combustibil1 enum('b','d'),out vnr varchar(20), out vmid int, out vaf year, out vcomb enum('d','b'))
begin

select nr_inmatriculare, marca.id_tara, an_fabricatie, combustibil into vnr, vmid, vaf, vcomb  from tara,marca,model,tip_motor, masina 
where tara.id_tara=marca.id_tara and marca.id_marca=model.id_marca and model.id_model=tip_motor.id_model and tip_motor.id_tip_motor=masina.id_tip_motor and
an_fabricatie=v_an and combustibil=v_combustibil1 and marca.id_tara=v_tara1; 


end;
//
delimiter ;

call cars1 (1,1997,'d',@a,@b,@c,@d);

错误1172:结果由多行组成

我认为解决方案应该是这样的:

delimiter //
create procedure cars (in v_tara1 int, in v_an year, in v_combustibil1 enum('b','d'))
begin
    declare lista varchar (1200) default '';
    declare ok int default 0;
    declare v_nr_inmatriculare varchar(8);
    declare v_tara int;
    declare v_an_fabricatie year;
    declare v_combustibil enum('d','b');
    declare c cursor for select nr_inmatriculare, marca.id_tara, an_fabricatie, combustibil from tara,marca,model,tip_motor, masina 
where tara.id_tara=marca.id_tara and marca.id_marca=model.id_marca and model.id_model=tip_motor.id_model and tip_motor.id_tip_motor=masina.id_tip_motor and
an_fabricatie=v_an and combustibil=v_combustibil1 and marca.id_tara=v_tara1; 
 declare continue handler for not found set ok=1;

open c;
    bucla: loop
        fetch c into v_nr_inmatriculare, v_tara, v_an_fabricatie, v_combustibil;
            if ok =1 then leave bucla;
        else
        set lista = concat(v_nr_inmatriculare,' ', v_tara,' ', v_an_fabricatie,' ',v_combustibil,';',lista);
            end if;

    end loop;
   select lista; 
        close c;
end;
//
delimiter ;

call cars (1,1997,'d');

问题是:你知道输出表而不是列表的任何解决方案吗?

0 个答案:

没有答案