gpt4 book ai didi

mysql - 过程语法错误

转载 作者:行者123 更新时间:2023-11-29 07:43:11 25 4
gpt4 key购买 nike

我在尝试在 MySQL 上创建过程时遇到以下错误:

Error Code: 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 'insert into objetivo.historico (id_aluno, id_turma, ano, bim1) values (a_id, a_t' at line 5

以及程序中的其他几行。问题是我看不出我在哪里犯了错误,因为出现错误的代码的某些部分在过程中重复出现而没有错误。

这是纯代码:

create procedure objetivo.p_atu_historico (in a_id integer, in a_turma
integer, in a_data date, in a_nota double, in a_bim integer)
begin
if(select count(id) from objetivo.historico where id_aluno = a_id and id_turma = a_turma and ano = Format(a_data, '%Y') )= 0 then
CASE a_bim
WHEN 1 THEN (insert into objetivo.historico (id_aluno, id_turma, ano, bim1) values (a_id, a_turma, Format(a_data, '%Y'), a_nota))
WHEN 2 THEN (insert into objetivo.historico (id_aluno, id_turma, ano, bim2) values (a_id, a_turma, Format(a_data, '%Y'), a_nota))
WHEN 3 THEN (insert into objetivo.historico (id_aluno, id_turma, ano, bim3) values (a_id, a_turma, Format(a_data, '%Y'), a_nota))
WHEN 4 THEN (insert into objetivo.historico (id_aluno, id_turma, ano, bim4) values (a_id, a_turma, Format(a_data, '%Y'), a_nota))
END CASE;

ELSEIF (select count(id) from objetivo.historico where id_aluno = a_id and id_turma = a_turma and ano = Format(a_data, '%Y')) <> 0 THEN
CASE a_bim
WHEN 1 THEN (UPDATE objetivo.historico SET bim1 = a_nota WHERE id_aluno = a_id and id_turma = a_turma and ano = Format(a_data, '%Y'))
WHEN 2 THEN (UPDATE objetivo.historico SET bim2 = a_nota WHERE id_aluno = a_id and id_turma = a_turma and ano = Format(a_data, '%Y'))
WHEN 3 THEN (UPDATE objetivo.historico SET bim3 = a_nota WHERE id_aluno = a_id and id_turma = a_turma and ano = Format(a_data, '%Y'))
WHEN 4 THEN (UPDATE objetivo.historico SET bim4 = a_nota WHERE id_aluno = a_id and id_turma = a_turma and ano = Format(a_data, '%Y'))
END CASE;
END IF;
end;

这是返回错误的行的打印屏幕:

The errors

编辑

这就是当我将分号放在每个 WHEN 语句末尾时发生的情况:

Errors2

最佳答案

您的过程中有一个小语法错误。您需要删除多余的括号并在每个语句后面插入分号。就像这样:

create procedure objetivo.p_atu_historico (in a_id integer, in a_turma
integer, in a_data date, in a_nota double, in a_bim integer)
begin
if(select count(id) from objetivo.historico where id_aluno = a_id and id_turma = a_turma and ano = Format(a_data, '%Y') )= 0 then
CASE a_bim
WHEN 1 THEN insert into objetivo.historico (id_aluno, id_turma, ano, bim1) values (a_id, a_turma, Format(a_data, '%Y'), a_nota);
WHEN 2 THEN insert into objetivo.historico (id_aluno, id_turma, ano, bim2) values (a_id, a_turma, Format(a_data, '%Y'), a_nota);
WHEN 3 THEN insert into objetivo.historico (id_aluno, id_turma, ano, bim3) values (a_id, a_turma, Format(a_data, '%Y'), a_nota);
WHEN 4 THEN insert into objetivo.historico (id_aluno, id_turma, ano, bim4) values (a_id, a_turma, Format(a_data, '%Y'), a_nota);
END CASE;

ELSEIF (select count(id) from objetivo.historico where id_aluno = a_id and id_turma = a_turma and ano = Format(a_data, '%Y')) <> 0 THEN
CASE a_bim
WHEN 1 THEN UPDATE objetivo.historico SET bim1 = a_nota WHERE id_aluno = a_id and id_turma = a_turma and ano = Format(a_data, '%Y');
WHEN 2 THEN UPDATE objetivo.historico SET bim2 = a_nota WHERE id_aluno = a_id and id_turma = a_turma and ano = Format(a_data, '%Y');
WHEN 3 THEN UPDATE objetivo.historico SET bim3 = a_nota WHERE id_aluno = a_id and id_turma = a_turma and ano = Format(a_data, '%Y');
WHEN 4 THEN UPDATE objetivo.historico SET bim4 = a_nota WHERE id_aluno = a_id and id_turma = a_turma and ano = Format(a_data, '%Y');
END CASE;
END IF;
end;

关于mysql - 过程语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28507080/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com