简体   繁体   中英

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. 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.

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:

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.

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 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM