python 3.6 连接 oracle 后 怎么读取数据和列名
目前我是这样连接的,没问题。但是没有列名称。importcx_Oracleasoracle#connectoracledatabasedb=oracle.connect(...
目前我是这样连接的,没问题。但是没有列名称。
import cx_Oracle as oracle
# connect oracle database
db = oracle.connect('scott/0000@192.168.146.1:1521/orcl')
# create cursor
cursor = db.cursor()
# execute sql
cursor.execute('select * from R_TRAIN')
# fetch data
data = cursor.fetchall()
# close cursor and oracle
cursor.close()
db.close() 展开
import cx_Oracle as oracle
# connect oracle database
db = oracle.connect('scott/0000@192.168.146.1:1521/orcl')
# create cursor
cursor = db.cursor()
# execute sql
cursor.execute('select * from R_TRAIN')
# fetch data
data = cursor.fetchall()
# close cursor and oracle
cursor.close()
db.close() 展开
1个回答
展开全部
def query(self, sql):
connect = self.connect()
cur = connect.cursor()
cur.execute(sql)
index = cur.description
result = []
for res in cur.fetchall():
row = {}
for i in range(len(index)-1):
row[index[i][0]] = res[i]
result.append(row)
connect.close()
return result
这个方法返回查询结果就是带字段名的{‘字段名’:‘值’}
connect = self.connect()
cur = connect.cursor()
cur.execute(sql)
index = cur.description
result = []
for res in cur.fetchall():
row = {}
for i in range(len(index)-1):
row[index[i][0]] = res[i]
result.append(row)
connect.close()
return result
这个方法返回查询结果就是带字段名的{‘字段名’:‘值’}
追问
能不能说点新的,这个网上有
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询