python读取数据库怎么把列名显示出来
3个回答
展开全部
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
这个方法返回查询结果就是带字段名的{‘字段名’:‘值’}
2017-08-28
展开全部
select column_name from all_tab_columns
where TABLE_NAME = 'your_table '
import cx_Oracle
con = cx_Oracle.connect( "picc", "181818","orcl")
cursor = con.cursor()
column_data_types = cursor.execute('select * from tradesummary')
result = cursor.fetchall()
for record in result:
print record
cursor.close()
con.close()
where TABLE_NAME = 'your_table '
import cx_Oracle
con = cx_Oracle.connect( "picc", "181818","orcl")
cursor = con.cursor()
column_data_types = cursor.execute('select * from tradesummary')
result = cursor.fetchall()
for record in result:
print record
cursor.close()
con.close()
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
df = pd.DataFrame(......)
df.columns 获得列名
df.columns 获得列名
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询