开发者

MySQL :: Run SQL statement within Variable

开发者 https://www.devze.com 2023-01-31 04:16 出处:网络
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:

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消