MySQL :: Run SQL statement within Variable
I am creating a stored procedure in MySQL 5.1.40 which needs to run a lot of SQL statements.
One particular statement that is often repeated clears a temp table:
DELETE FROM w_projection_temp WHERE user_id = uid;
The uid variable is an IN parameter for the S开发者_如何学编程P.
Is it possible to assign that entire SQL statement to another variable, and then somehow run (evaluate?) that new variable? eg:
DECLARE clear_temp VARCHAR;
SET clear_temp = 'DELETE FROM w_projection_temp WHERE user_id = uid;'
MTIA
PREPARE clear_temp FROM "DELETE FROM w_projection_temp WHERE user_id = ?"
EXECUTE clear_temp USING uid;
DEALLOCATE PREPARE clear_temp;
精彩评论