zoukankan      html  css  js  c++  java
  • python 查询表数据以字典展示,将表字段作为key

    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
    if __name__ == '__main__':
    print(OraclePy('QAMODIFY','ubyledc6','192.168.14.143',1530,'isdb').getDefultRate('ol_alipay_rate'))

     注:使用cx_Oracle.makedsn连接oracle数据库时,如果用Service name不用SID,应该如下传参。

          dns_tns=cx_Oracle.makedsn('host',port,service_name='service_name')

  • 相关阅读:
    mongoDB安装配置
    linux-批量修改目录下后缀shell
    备份mysql的shell
    mysql_DML_索引、视图
    mysql_存储过程
    mysql_备份_mysqldump
    mysql_DCL_grant/revoke
    mysql_DML_select_子查询
    mysql_DML_select_union
    mysql_DML_select_聚合join
  • 原文地址:https://www.cnblogs.com/wsy0202/p/13275207.html
Copyright © 2011-2022 走看看