MYSQL 在触发器上调用 SELECT CASE 内的存储过程
我坚持在触发器上的 SELECT CASE 内调用存储过程,它给了我以下错误:
[Err] 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 'empata(NEW.eqvis))
WHEN 'loc' THEN pierde(NEW.eqvis)
WHEN 'vis' THEN g' at line 16
这是代码:
DELIMITER |
CREATE TRIGGER updpartido AFTER UPDATE ON partidos
FOR EACH ROW
BEGIN
SET @vgls = vgoles(NEW.eqvis);
SET @lgls = vgoles(NEW.eqloc);
SET @vglsec = vgolesec(NEW.eqvis);
SET @lglsec = vgolesec(NEW.eqloc);
SELECT CASE
WHEN @vgls=@lgls THEN "emp"
WHEN @vgls>@lgls THEN "loc"
WHEN @vgls<@lgls THEN "vis"
END
INTO @st;
SELECT CASE @st
WHEN 'emp' THEN CALL empata(NEW.eqvis)
WHEN 'loc' THEN CALL pierde(NEW.eqvis)
WHEN 'vis' THEN CALL gana(NEW.eqvis)
END
INTO @dat;
SELECT CASE @st
WHEN 'emp' THEN CALL empata(NEW.eqloc)
WHEN 'vis' THEN CALL pierde(NEW.eqloc)
WHEN 'loc' THEN CALL gana(NEW.eqloc)
END
INTO @dat2;
UPDATE equipos SET gf=@vgls,gc=@vglsec WHERE id=NEW.eqvis;
UPDATE equipos SET gf=@lgls,gc=@lglsec WHERE id=NEW.eqloc;
END;
|
但是,如果我删除“CALL”,触发器会添加,但是当我进行一些更新时,它会给我“找不到函数”的错误,因为我将它们作为存储过程而不是函数,因为我不会返回任何内容......
任何非常感谢帮助!
im stuck on calling stored procedures inside a SELECT CASE on a Trigger, it gaves me the following error:
[Err] 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 'empata(NEW.eqvis))
WHEN 'loc' THEN pierde(NEW.eqvis)
WHEN 'vis' THEN g' at line 16
Here is the code:
DELIMITER |
CREATE TRIGGER updpartido AFTER UPDATE ON partidos
FOR EACH ROW
BEGIN
SET @vgls = vgoles(NEW.eqvis);
SET @lgls = vgoles(NEW.eqloc);
SET @vglsec = vgolesec(NEW.eqvis);
SET @lglsec = vgolesec(NEW.eqloc);
SELECT CASE
WHEN @vgls=@lgls THEN "emp"
WHEN @vgls>@lgls THEN "loc"
WHEN @vgls<@lgls THEN "vis"
END
INTO @st;
SELECT CASE @st
WHEN 'emp' THEN CALL empata(NEW.eqvis)
WHEN 'loc' THEN CALL pierde(NEW.eqvis)
WHEN 'vis' THEN CALL gana(NEW.eqvis)
END
INTO @dat;
SELECT CASE @st
WHEN 'emp' THEN CALL empata(NEW.eqloc)
WHEN 'vis' THEN CALL pierde(NEW.eqloc)
WHEN 'loc' THEN CALL gana(NEW.eqloc)
END
INTO @dat2;
UPDATE equipos SET gf=@vgls,gc=@vglsec WHERE id=NEW.eqvis;
UPDATE equipos SET gf=@lgls,gc=@lglsec WHERE id=NEW.eqloc;
END;
|
But if i remove the "CALL" the Triggers adds but when i do some update it gives me the error of "FUNCTION not found" since i made them as stored procedures and not as functions because im not going to return nothing...
Any help is very appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将过程
empata
、pierde
和gana
转换为函数并按照下面第一个示例中的编码使用:我测试了以下场景并它们不起作用:
至少,它们对我不起作用。
You can convert your procedures
empata
,pierde
, andgana
into functions and use as coded in the first example below:I tested the following scenarios and they didn't work:
At the very least, they didn't work for me.
尽管我不是 MySQL 专家,但我还是要冒险寻找答案:
我不认为你可以在 select 语句中调用存储过程,而 select 语句的输出存储在变量中;或者更通俗地说:你不能同时吹气和吸吮。您要么有一个 select 语句,其目的是返回一些记录,要么对数据执行某种处理,但不能将两者交织在一起。
如果您将
CALL
语句分开,我认为它应该可以工作。您可以在into @...
下面进行检查并调用适当的存储过程。I am going to adventure an answer even though I'm not a MySQL guy:
I don't think you can call stored procedures within a select statement whose output is stored in a variable; or more colloquially: You can't blow and suck at the same time. You either have have a select statement whose purpose is to return some records or you execute some kind of process on your data, but you can't have both intertwined.
If you separate the
CALL
statements I think it should work. You can do the check below theinto @...
and call the appropriate stored proc.