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.linux下mysql安装配置初学(二)ubuntu安装mysql-gui-tools相关资讯 mysql
- 数据库服务器 MySQL (08/15/2013 06:50:23)
- MySQL 5.6 GA 及逃亡潮 (02/08/2013 14:36:35)
- MySQL 5.5.22、5.1.62、5.0.96全线 (03/22/2012 19:03:49)
| - MySQL Administrator连接VMWare下 (05/24/2013 09:20:58)
- MySQL 5.1.68 发布 (02/05/2013 08:37:47)
- CentOS 5.2+MySQL+Heartbeat双机互 (01/29/2012 11:16:55)
|
本文评论 查看全部评论 (0)