MYSQL 在触发器上调用 SELECT CASE 内的存储过程

发布于 2024-12-11 06:59:49 字数 1478 浏览 0 评论 0原文

我坚持在触发器上的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尐偏执 2024-12-18 06:59:49

您可以将过程 empatapierdegana 转换为函数并按照下面第一个示例中的编码使用:

-- works
SET @st = 'loc';
SELECT CASE @st
  WHEN 'loc' THEN function_(@st)
END
INTO @dat;
SELECT @dat;

我测试了以下场景并它们不起作用:

-- won't work
SET @st = 'loc';
IF @st = 'loc' THEN
    function_(@st);
END IF;

-- won't work
SET @st = 'loc';
SELECT CASE @st
  WHEN 'loc' THEN CALL stored_procedure_(@st)
END
INTO @dat;
SELECT @dat;

-- won't work
SET @st = 'loc';
IF @st = 'loc' THEN
    CALL stored_procedure_(@st);
END IF;

至少,它们对我不起作用。

You can convert your procedures empata, pierde, and gana into functions and use as coded in the first example below:

-- works
SET @st = 'loc';
SELECT CASE @st
  WHEN 'loc' THEN function_(@st)
END
INTO @dat;
SELECT @dat;

I tested the following scenarios and they didn't work:

-- won't work
SET @st = 'loc';
IF @st = 'loc' THEN
    function_(@st);
END IF;

-- won't work
SET @st = 'loc';
SELECT CASE @st
  WHEN 'loc' THEN CALL stored_procedure_(@st)
END
INTO @dat;
SELECT @dat;

-- won't work
SET @st = 'loc';
IF @st = 'loc' THEN
    CALL stored_procedure_(@st);
END IF;

At the very least, they didn't work for me.

恋竹姑娘 2024-12-18 06:59:49

尽管我不是 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 the into @... and call the appropriate stored proc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文