首页 > 编程语言 > 详细

python 查询表数据以字典展示,将表字段作为key

时间:2020-07-09 18:41:20      阅读:94      评论:0      收藏:0      [点我收藏+]

 

import cx_Oracle as cx

class OraclePy():
    def __init__(self,userName,password,ip,host,SID):
        self.userName = userName
        self.password = password
        self.host = ip
        # self.con = cx.connect(userName,password,host)
        self.con = cx.connect(userName, password, cx.makedsn(ip, host, SID))
        self.cursor = self.con.cursor()

    def getData(self,sql,offlineTranAmount,onlineTranAmount):
        self.cursor.execute(sql)
        col = []
        resultSets = []
for i in self.cursor.description:
            col.append(i[0])
        for data in self.cursor.fetchall():
            list2 = (list(data))
            resultSets.append(dict(map(lambda x, y: [x, y], col, list2)))
     return resultSets

 

python 查询表数据以字典展示,将表字段作为key

原文:https://www.cnblogs.com/wsy0202/p/13275207.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!