MYSQL: execute string
Sometimes we need to execute dynamic sql. This is recipe:
PREPARE stmt FROM 'UPDATE stat
SET r_? = r_? - 1, l = l - 1, p_? = p_? - OLD.value
WHERE date(OLD.datetime) = date;';
EXECUTE stmt USING @old_status, @old_status, @old_status, @old_status;
But you can't use it in triggers and fuctions, but in procedures you can.
There is no workaround to use dynamic SQL in triggers by calling procedures. MySQL knows it! But variable helps me =)
Comments
comments powered by Disqus