开发提了一个需要分页的存储过程需求,刚来时理解是,只要带入一个变量,根据变量计算下值,就直接分页实现了...可结果,创建存储过程的时候报错了...查了很多资料,后来才得知,limit后面不能带变量.于是就想到直接吧带入参数进行计算.在吧带入参数进行分页...
把大概过程贴一下...自己也记录一下:
MysqL>delimiter //
MysqL> create procedure t2 ( d1 int)
-> begin
-> set @a=(d1-1)*10;
-> select * from t1 limt @a,1;
-> end//
ERROR 1064 (42000): You have an error in your sql Syntax; check the manual that corresponds to your MysqL server version for the right Syntax to use near '@a,1;
end' at line 4
MysqL>create procedure t2 ( d1 int)
->begin
->set d1=(d1-1)*10;
->select * from t1 limit d1,1;
->end//
Query OK, 0 rows affected (0.00 sec)
MysqL> select * from t1;//
+------+-------+------+
| id | cart | name |
+------+-------+------+
| 1 | 001 | jak |
| 2 | NULL | mak |
| 3 | dd | kk |
| 4 | 2d | dkk |
| 5 | 2ddw2 | 9jd2 |
| 6 | 2ddw2 | 9jd2 |
| 7 | 2ddw2 | 9jd2 |
| 8 | 2ddw2 | 9jd2 |
| 9 | 2ddw2 | 9jd2 |
| 10 | 2ddw2 | 9jd2 |
+------+-------+------+
10 rows in set (0.00 sec)
MysqL> call t2(3);//
+------+-------+------+
| id | cart | name |
+------+-------+------+
| 5 | 2ddw2 | 9jd2 |
| 6 | 2ddw2 | 9jd2 |
+------+-------+------+
2 rows in set (0.00 sec)
MysqL> select * from t1 limit 3,2;//
+------+-------+------+
| id | cart | name |
+------+-------+------+
| 4 | 2d | dkk |
| 5 | 2ddw2 | 9jd2 |
+------+-------+------+
2 rows in set (0.00 sec)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。