Dynamic MySQL with local variables

前端 未结 1 1291
太阳男子
太阳男子 2020-12-19 20:41

How can I use dynamic SQL statements in MySQL database and without using session variables?

Right now I have such a code (in MySQL stored procedure):

(...)         


        
相关标签:
1条回答
  • Sorry, prepared statements in MySQL are session-global. According to http://dev.mysql.com/doc/refman/5.1/en/sql-syntax-prepared-statements.html, "A prepared statement is also global to the session."

    And there's no other way (besides prepared statements) to execute dynamic SQL in MySQL 5.x.

    So you can of course replace "@s" above, but AFAIK you're stuck with @SelectedId.

    In MySQL 6.x, there is a feature planned which will add an "EXECUTE IMMEDIATE" statement which will execute dynamic SQL. See http://forge.mysql.com/worklog/task.php?id=2793.

    0 讨论(0)
提交回复
热议问题