简体   繁体   English

如何使用fetchmany()获取下一组结果?

[英]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.

相关问题 cursor.fetchmany 与 DECLARE BINARY CURSOR 和 FETCH - cursor.fetchmany vs DECLARE BINARY CURSOR and FETCH PuLP如何根据先前的结果设置下一个变量? - PuLP how to set next variable according to previous results? 如何使用 fetchmany 将 mysql 表转储到 csv 中 - How to dump mysql table into csv using fetchmany 如何使用 Azure DevOps / VSTS 获取 python 中的查询结果 - How to use Azure DevOps / VSTS to fetch query results in python Python - 如何防止MySQLdb游标更新干扰fetchmany? - Python - How to prevent MySQLdb cursor update interfering with fetchmany? 如何使用set_random_seed获得相同的结果 - how to use set_random_seed to get same results 如何将值列表乘以值的数据帧,然后使用这些结果乘以数据帧中的下一行值? - How do i multiply a list of values by a dataframe of values then use those results to multiply by the next row of values in the dataframe? 如何从 dataframe 中的下一列中获取数据 - How to fetch the data from next column in a dataframe 如何创建循环,或者将以前的SELECT语句的结果用于下一个SELECT语句? - How do I create a loop, or a way to use the results of previous SELECT statements into the next SELECT statement? 如何获取 python 字典中第一行和下一行的键 - How to fetch key in the first line and next to next line in python dictionary
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM