我想检索我的 Sqlite3 数据库的前 100 行:
connection = sqlite3.connect('aktua.db')
cursor = connection.cursor()
print('Actual \tCliente \tHistórica')
cursor.execute("SELECT * FROM Referencias WHERE r_aktua LIKE '%K'").fetchmany(size=100)
for row in cursor:
print('%s \t%s \t%s' % row)
cursor.close()
connection.close()
我的代码检索数据库的所有行 (+4000)。
我读过 sqlite3.Cursor.fetchmany Docs和 SQLite Python Tutorial .
怎么了?
最佳答案
用这个来限制sql选择:
"SELECT * FROM Referencias WHERE r_aktua LIKE '%K' LIMIT 100"
或者将您的代码更改为:
rows = cursor.execute("SELECT * FROM Referencias WHERE r_aktua LIKE '%K'").fetchmany(size=100)
for row in rows:
print('%s \t%s \t%s' % row)
关于python - Sqlite3 中的 cursor.fechtmany(size=cursor.arraysize),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22299793/