错误代码= 1064的过程中的SQL错误

时间:2015-07-24 10:18:04

标签: mysql sql

我使用MySQL并且在插入此程序时出错,下面显示的是错误,如果有人可以提供帮助的话。

    CREATE PROCEDURE esperance_gain
BEGIN
declare i int(10);
declare E int(20);
set E:=0;
Select count(*) into nb_lignes from questionnaire;
set i:=1;
while (i<=nb_lignes) LOOP
select question4,question7,question8 from questionnaire where i=identifiant;
case question7
when question7='moins de 1dt' then 
case question8
when question8='certain' then set E:=E+0.5;
when question8='fort probable' then set E:=E+(0.5*0.75);
when question8='en fonction des prochains jeux' then set E:=E+(0.5*0.5);
when question8='peu probable' then set E:=E+(0.5*0.25);
when question8='probabilité nulle' then set E:=E+(0.5*0);
end case;
when question7='entre 1dt et 5dt' then
case question8
when question8='certain' then set E:=E+3;
when question8='fort probable' then set E:=E+(3*0.75);
when question8='en fonction des prochains jeux' then set E:=E+(3*0.5);
when question8='peu probable' then set E:=E+(3*0.25);
when question8='probabilité nulle' then set E:=E+(3*0);
end case;
when question7='entre 5dt et 15dt' then
case question8
when question8='certain' then set E:=E+10;
when question8='fort probable' then set E:=E+(10*0.75);
when question8='en fonction des prochains jeux' then set E:=E+(10*0.5);
when question8='peu probable' then set E:=E+(10*0.25);
when question8='probabilité nulle' then set E:=E+(10*0);
end case;
when question7='entre 15dt et 20dt' then
case question8
when question8='certain' then set E:=E+17.5;
when question8='fort probable' then set E:=E+(17.5*0.75);
when question8='en fonction des prochains jeux' then set E:=E+(17.5*0.5);
when question8='peu probable' then set E:=E+(17.5*0.25);
when question8='probabilité nulle' then set E:=E+(17.5*0);
end case;
when question7='plus de 20dt' then
case question8
when question8='certain' then 
case question4
when question4='Oui' then set E:=E+(60*1);
when question4='Parfois' then set E:=E+(35*1);
when question4='Non' then set E:=E+(20*1);
end case;
when question8='fort probable' then 
case question4
when question4='Oui' then set E:=E+(60*0.75);
when question4='Parfois' then set E:=E+(35*0.75);
when question4='Non' then set E:=E+(20*0.75);
end case;
when question8='en fonction des prochains jeux' then 
case question4
when question4='Oui' then set E:=E+(60*0.5);
when question4='Parfois' then set E:=E+(35*0.5);
when question4='Non' then set E:=E+(20*0.5);
end case;
when question8='peu probable' then 
case question4
when question4='Oui' then set E:=E+(60*0.25);
when question4='Parfois' then set E:=E+(35*0.25);
when question4='Non' then set E:=E+(20*0.25);
end case;
when question8='probabilité nulle' then
case question4
when question4='Oui' then set E:=E+(60*0);
when question4='Parfois' then set E:=E+(35*0);
when question4='Non' then set E:=E+(20*0);
end case;
end case;
set i:=i+1;
END LOOP;
END 

显示错误:

#1064 - 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
declare i int(10);
declare E int(20);
set E:=0;
Select count(*) into n' at line 2

我在oracle10g中尝试过它可以正常工作但是MySQL让我很生气

2 个答案:

答案 0 :(得分:2)

你有一些丢失的关键词,也像vhu已经说你错过了括号。

我建议设置分隔符,以便过程体和使用过的;没有问题。您没有声明名称为nb_lignes的变量,我将其添加到过程中。你错过了一个end case,第二个循环是 没有必要我删除它并用END LOOP替换END WHILE

我希望它有所帮助。

DELIMITER \\

CREATE PROCEDURE esperance_gain()
BEGIN
    declare i int(10);
    declare E int(20);
    declare nb_lignes int;
    set E:=0;
    Select count(*) into nb_lignes from questionnaire;
    set i:=1;
    while (i<=nb_lignes) do 
        select question4,question7,question8 from questionnaire where i=identifiant;
        case question7
            when question7='moins de 1dt' then 
            case question8
                when question8='certain' then set E:=E+0.5;
                when question8='fort probable' then set E:=E+(0.5*0.75);
                when question8='en fonction des prochains jeux' then set E:=E+(0.5*0.5);
                when question8='peu probable' then set E:=E+(0.5*0.25);
                when question8='probabilité nulle' then set E:=E+(0.5*0);
            end case;
            when question7='entre 1dt et 5dt' then
            case question8
                when question8='certain' then set E:=E+3;
                when question8='fort probable' then set E:=E+(3*0.75);
                when question8='en fonction des prochains jeux' then set E:=E+(3*0.5);
                when question8='peu probable' then set E:=E+(3*0.25);
                when question8='probabilité nulle' then set E:=E+(3*0);
            end case;
            when question7='entre 5dt et 15dt' then
            case question8
                when question8='certain' then set E:=E+10;
                when question8='fort probable' then set E:=E+(10*0.75);
                when question8='en fonction des prochains jeux' then set E:=E+(10*0.5);
                when question8='peu probable' then set E:=E+(10*0.25);
                when question8='probabilité nulle' then set E:=E+(10*0);
            end case;
            when question7='entre 15dt et 20dt' then
            case question8
                when question8='certain' then set E:=E+17.5;
                when question8='fort probable' then set E:=E+(17.5*0.75);
                when question8='en fonction des prochains jeux' then set E:=E+(17.5*0.5);
                when question8='peu probable' then set E:=E+(17.5*0.25);
                when question8='probabilité nulle' then set E:=E+(17.5*0);
            end case;
            when question7='plus de 20dt' then
            case question8
                when question8='certain' then 
                case question4
                    when question4='Oui' then set E:=E+(60*1);
                    when question4='Parfois' then set E:=E+(35*1);
                    when question4='Non' then set E:=E+(20*1);
                end case;
                when question8='fort probable' then 
                case question4
                    when question4='Oui' then set E:=E+(60*0.75);
                    when question4='Parfois' then set E:=E+(35*0.75);
                    when question4='Non' then set E:=E+(20*0.75);
                end case;
                when question8='en fonction des prochains jeux' then 
                case question4
                    when question4='Oui' then set E:=E+(60*0.5);
                    when question4='Parfois' then set E:=E+(35*0.5);
                    when question4='Non' then set E:=E+(20*0.5);
                end case;
                when question8='peu probable' then 
                case question4
                    when question4='Oui' then set E:=E+(60*0.25);
                    when question4='Parfois' then set E:=E+(35*0.25);
                    when question4='Non' then set E:=E+(20*0.25);
                end case;
                when question8='probabilité nulle' then
                case question4
                    when question4='Oui' then set E:=E+(60*0);
                    when question4='Parfois' then set E:=E+(35*0);
                    when question4='Non' then set E:=E+(20*0);
                end case;
            end case;
        end case;
    set i:=i+1;
    END WHILE;
END \\

DELIMITER ;

答案 1 :(得分:1)

您在程序名称后缺少括号:

CREATE PROCEDURE esperance_gain()

MySQL中的相关部分manual