Tri*_*max 4 python sqlite fetch
我想检索 Sqlite3 数据库的前 100 行:
\n\nconnection = sqlite3.connect(\'aktua.db\')\ncursor = connection.cursor()\n\nprint(\'Actual \\tCliente \\tHist\xc3\xb3rica\')\ncursor.execute("SELECT * FROM Referencias WHERE r_aktua LIKE \'%K\'").fetchmany(size=100)\n\nfor row in cursor:\n print(\'%s \\t%s \\t%s\' % row)\n\ncursor.close()\nconnection.close()\n
Run Code Online (Sandbox Code Playgroud)\n\n我的代码检索数据库的所有行(+4000)。
\n我已阅读sqlite3.Cursor.fetchmany 文档和SQLite Python 教程。
怎么了?
\n使用它来限制 sql 选择:
"SELECT * FROM Referencias WHERE r_aktua LIKE '%K' LIMIT 100"
Run Code Online (Sandbox Code Playgroud)
或者将您的代码更改为:
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)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2385 次 |
最近记录: |