MySQL ::在Variable中运行SQL语句 [英] MySQL :: Run SQL statement within Variable
本文介绍了MySQL ::在Variable中运行SQL语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在MySQL 5.1.40中创建一个存储过程,该过程需要运行许多SQL语句.
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;
uid 变量是SP的IN参数.
The uid variable is an IN parameter for the SP.
是否可以将整个SQL语句分配给另一个变量,然后以某种方式运行(评估?)该新变量?例如:
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;
这篇关于MySQL ::在Variable中运行SQL语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文