[英]How to use fetchmany() to fetch the next set of results?
I want to fetch a hundred of results from MySql using fetchmany(100) in Python. 我想在Python中使用fetchmany(100)从MySql中获取一百个结果。 But I am wondering if there's a way to fetch the next set of results in case what I want is not available in the fetched results.
但是我想知道是否有一种方法可以提取下一组结果,以防在提取的结果中找不到我想要的结果。 So it will be something like, fetch the next 100 results.
这样就可以获取下100个结果。
Is this possible? 这可能吗? And if yes then how can it be done?!
如果是的话,那怎么办?
Instead of using fetchmany(), you can use fetchall(), but include in your select query the following: 除了使用fetchmany(),还可以使用fetchall(),但在您的选择查询中包括以下内容:
SELECT * from data limit 00,30;
The 00
indicates the position The 30
indicates the number of the rows you want to output as the result. 00
表示位置30
表示要作为结果输出的行数。
Hence, you can make introduce the position using a variable that increases every time you want to fetch more results. 因此,您可以使用每次获取更多结果时都会增加的变量来介绍位置。
Eg 例如
position= 00
while True:
nothing = input("Do you want more input?")
data = c.execute("SELECT * from data limit {}, 50".format(amount))
data = c.fetchall()
position += 50
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.