这是我的代码.我想找到一种方法,将查询结果作为字典列表而不是元组列表返回.似乎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()
Run Code Online (Sandbox Code Playgroud)