Can a stored procedure plus a sql query be executed from within a trigger?
procedure plus query
SET @tmp = (SELECT fvalue FROM ftable WHERE id=2);
SET @SQL = CONCAT('INSERT INTO ',@tmp,' VALUES (''buhambug'')');
PREPARE stmt FROM @SQL;
EXECUTE stmt;
If so what are the rules and links to examples? I have’t been able to find any.
Yeah, you can call a stored procedure from a trigger like this:
Note the ending delimiter. If
;is the default delimiter inside the trigger as well, then it won’t work, for MySQL will treat each command separately and throw error. You want the entire code inside the trigger to be executed together. hence declare a different delimiter, like $$ prior to defining the trigger, throughDelimiter $$. Then,;will work correctly inside the the trigger. After you terminate the trigger through $$, don’t forget to restore the default delimiter.