Python 如何在Oracle中获取特定(主)键值之后的数据?

Python 如何在Oracle中获取特定(主)键值之后的数据?,python,database,oracle,fetch,Python,Database,Oracle,Fetch,我正在编写以下代码。我相信这可能是一个疑问 dsn_tns = cx_Oracle.makedsn(database_host, database_port, database_service) connection = cx_Oracle.connect(database_username, database_password, dsn_tns, cx_Oracle.SYSDBA) print("Database connected") cursor = connection.cursor()

我正在编写以下代码。我相信这可能是一个疑问

dsn_tns = cx_Oracle.makedsn(database_host, database_port, database_service)
connection = cx_Oracle.connect(database_username, database_password, dsn_tns, cx_Oracle.SYSDBA)
print("Database connected")
cursor = connection.cursor()
cursor.execute("SELECT * FROM " + database_table)
records = cursor.fetchall()

有人有改进的想法吗?

有。您可以使用这样的查询

SELECT * FROM tbl WHERE pk >= some_value;
表上的主键由索引备份,因此WHERE子句中指定的搜索和筛选作业是有效的。数据库找到满足条件的第一行,然后按顺序读取其余行。这叫做索引范围扫描

Pro提示:避免使用
SELECT*
,而是使用
SELECT col,col2,col3
,给出您实际需要的表列的名称。它节省了数据库服务器上的工作,并使您的查询对表中未来可能发生的更改更具弹性