当前位置: 代码迷 >> python >> Sqlite3中的cursor.fechtmany(size = cursor.arraysize)
  详细解决方案

Sqlite3中的cursor.fechtmany(size = cursor.arraysize)

热度:69   发布时间:2023-07-14 08:58:22.0

我想检索我的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)。
我已经阅读了和 。

怎么了?

使用此限制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)