Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mysql stored procedure paging

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Mysql5.6.20 version

The developer put forward a requirement for a stored procedure that needs to be paged. When I first came here, I understood that as long as I brought in a variable and calculated the lower value according to the variable, I realized paging directly. But as a result, an error was reported when creating the stored procedure. Checked a lot of data, and later learned that limit can not be followed by variables. So I thought of directly bringing in the parameters for calculation. In the bar, bring in the parameters for paging.

Post the approximate process. Write down for yourself:

Mysql > delimiter / /

Mysql > create procedure T2 (D1 int)

-> begin

-> set @ a = (D1-1) * 10

-> select * from T1 limt @ aMagne1

-> 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 dint 1

End' at line 4

Mysql > create procedure T2 (D1 int)

-> begin

-> set D1 = (D1-1) * 10

-> select * from T1 limit D1 minute 1

-> end//

Query OK, 0 rows affected (0.00 sec)

Mysql > select * from t1bot /

+-+

| | 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 3pm 2lash /

+-+

| | id | cart | name | |

+-+

| | 4 | 2d | dkk |

| | 5 | 2ddw2 | 9jd2 |

+-+

2 rows in set (0.00 sec)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report