MySQL5.6.20版本
開發(fā)提了一個需要分頁的存儲過程需求,剛來時理解是,只要帶入一個變量,根據(jù)變量計算下值,就直接分頁實現(xiàn)了...可結(jié)果,創(chuàng)建存儲過程的時候報錯了...查了很多資料,后來才得知,limit后面不能帶變量.于是就想到直接吧帶入?yún)?shù)進(jìn)行計算.在吧帶入?yún)?shù)進(jìn)行分頁...
把大概過程貼一下...自己也記錄一下:
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)
新聞名稱:mysql存儲過程翻頁
網(wǎng)址分享:http://muchs.cn/article4/ghscie.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、網(wǎng)頁設(shè)計公司、響應(yīng)式網(wǎng)站、靜態(tài)網(wǎng)站、網(wǎng)站設(shè)計、微信公眾號
廣告
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源:
創(chuàng)新互聯(lián)