2

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 SP.

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

1
  • why do you want to make this dynamic - you got it right first time Commented Dec 15, 2010 at 5:10

1 Answer 1

2
PREPARE clear_temp FROM "DELETE FROM w_projection_temp WHERE user_id = ?"
EXECUTE clear_temp USING uid;
DEALLOCATE PREPARE clear_temp;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.