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!
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.
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.