Good day, there was a problem: depending on the id of the changed record, you need to call a certain MySQL function, I do a trigger.

Here is the trigger code:

DELIMITER $$ CREATE TRIGGER price_change after update ON `cms_flower`.oc_product BEGIN DECLARE @func varchar(10); SET @func = 'Call ' + NEW.product_id + '(' + NEW.price + ')'; exec(@func); END$$ DELIMITER ; 

Issues:

You have an error in your SQL syntax; If you’re on the right line, you’ll be able to use your vidar (10); SET @func = 'Call' + NEW.product_id + '(' + NEW.price + ')' 'at line 5

I do not know how to implement, help pzhlst

  • and this is exactly mysql , not mariadb ? - Nick Volynkin
  • @NickVolynkin is MariaDB, but it is MySQL-compatible for the most part. Apparently, TCA is interested in just a MySQL-compatible feature set. So the set of tags is very meaningful. - D-side Nov.
  • @ D-side ok, thanks. ) - Nick Volynkin

2 answers 2

The called function has the same name as in product_id ?

 SET @q = CONCAT('CALL ', NEW.product_id, '(', NEW.price, ')'); PREPARE s FROM @q; EXECUTE s; 

    @func is a user variable, you need DECLARE func varchar (10);

    Use prepared prepare / execute statements