这是我的代码。我想找到一种方法,将查询的结果作为字典列表而不是元组列表返回。似乎 cx_oracle 支持这一点,部分文档讨论了“绑定”。虽然我无法弄清楚它是如何工作的。
def connect():
dsn = cx_Oracle.makedsn("host", 1521, "sid")
orcl = cx_Oracle.connect('scott/tiger@' + dsn)
curs = orcl.cursor()
sql = "select * from sometable"
curs.execute(sql)
result = curs.fetchall()
for row in result:
print row[13] #CATEGORY field order
print row['CATEGORY'] # <- I want this to work ('CATEGORY' is the name of a field in the 'sometable' table)
curs.close()