80端口-80勃客♂
80端口悄悄提示:数据载入中……  
80端口悄悄提示:数据载入中……
时间记忆
80端口悄悄提示:数据载入中……
勃客管理
80端口悄悄提示:数据载入中……
用户公告
80端口悄悄提示:数据载入中……
我的相册
最新日志
80端口悄悄提示:数据载入中……
最新评论
80端口悄悄提示:数据载入中……
最新回复
80端口悄悄提示:数据载入中……
我的好友
站点信息
80端口悄悄提示:数据载入中……
 
2008-8-13 15:09:00
在mysql中使用动态SQL
mysql> set @sql_text:='select count(*) from test';
Query OK, 0 rows affected (0.00 sec)

mysql> prepare stmt from @sql_text;
Query OK, 0 rows affected (0.04 sec)
Statement prepared

mysql> execute stmt;
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (0.19 sec)

mysql> deallocate prepare stmt;
Query OK, 0 rows affected (0.00 sec)

在存储过程中改变@sql_text的值,则可以实现动态SQL的效果了。
但要注意,能够使用prepare的SQL是有限制的:
The following SQL statements can be used in prepared statements: CREATE TABLE, DELETE, DO, INSERT, REPLACE, SELECT, SET, UPDATE, and most SHOW statements. supported. ANALYZE TABLE, OPTIMIZE TABLE, and REPAIR TABLE are supported as of MySQL 5.0.23. Other statements are not yet supported.
80 | 阅读全文 | 回复(0) | 引用通告 | 编辑
发表评论:
80端口悄悄提示:数据载入中……
http://www.waasai.com/blog/f/80/index.html
Link to waasai.com Home