from: https://sourceforge.net/p/cx-oracle/mailman/message/27145597/

I'd do it with a "row factory", here are two examples, one which builds a dictionary, the other one builds a "named tuple" and is very similar to sqlite3.Row.

def makeDictFactory(cursor):
columnNames = [d[0] for d in cursor.description]
def createRow(*args):
return dict(zip(columnNames, args))
return createRow def makeNamedTupleFactory(cursor):
columnNames = [d[0].lower() for d in cursor.description]
import collections
Row = collections.namedtuple('Row', columnNames)
return Row
Then, just after the cs.execute() call, you can add:
cs.rowfactory = makeDictFactory(cs)
# or
cs.rowfactory = makeNamedTupleFactory(cs)
--
#Amaury Forgeot d'Arc

python oracle 查询返回字典的更多相关文章

  1. python mysql 查询返回字典结构

    cur = self.conn.cursor(MySQLdb.cursors.DictCursor)加上MySQLdb.cursors.DictCursor可以返回字典结构 {列名:值} class ...

  2. 让 Python 的1、数据库查询返回字典记录--- 2、利用zip函数将两个列表(list)组成字典(dict)

    让 Python 的数据库查询返回字典记录: https://yanbin.blog/python-database-query-return-dictionary-result/#more-9179 ...

  3. python调用数据返回字典dict数据的现象2

    python调用数据返回字典dict数据的现象2 思考: 话题1连接:https://www.cnblogs.com/zwgbk/p/10248479.html在打印和添加时候加上内存地址id(),可 ...

  4. python调用数据返回字典dict数据的现象1

    python调用数据返回字典dict数据的现象1 思考: 可以看到这两种情况,区别在于构造函数make()里赋值给字典dict的方式不同.使用相同的调用方式,而结果却完全不同.可以看到第二种情况才是我 ...

  5. 18.Django原生SQL语句查询返回字典

    在django中执行自定义语句的时候,返回的结果是一个tuple ,并我不是我所期望的dict.当结果是tuple 时,如果要取得数据,必须知道对应数据在结果集中的序号,用序号的方式去得到值. 如果是 ...

  6. Python查询Mysql时返回字典结构的代码

    Python查询Mysql时返回字典结构的代码 MySQLdb默认查询结果都是返回tuple,输出时候不是很方便,必须按照0,1这样读取,无意中在网上找到简单的修改方法,就是传递一个cursors.D ...

  7. Python中让MySQL查询结果返回字典类型的方法

    import pymysql host='localhost' user='root' passwd='root' port=3306 db='test' db=pymysql.connect( ho ...

  8. django原生sql查询如何返回字典格式

    django原生sql查询,默认返回的是元祖.如果想返回字典格式,需要自行封装: http://www.360doc.com/content/17/0802/11/9200790_676042880. ...

  9. oracle[insert 时报错: 单行子查询返回多行]

    -- 错误的写法 insert into t_b_partner_vehicle(id, partner_id, vehicle_id) (seq_t_b_partner_vehicle.nextva ...

随机推荐

  1. python实现简单的登陆认证(含简单的文件操作)

    需求: 让用户输入用户名密码 认证成功后显示欢迎信息 输错三次后退出程序 可以支持多个用户登录 (提示,通过列表存多个账户信息) 用户3次认证失败后,退出程序,再次启动程序尝试登录时,还是锁定状态(本 ...

  2. laravel文件上传报错 stream_socket_sendto():

    原因:文件超过限定大小或没指定临时目录 修改php.ini配置 file_uploads = On ; Temporary directory for HTTP uploaded files (wil ...

  3. 网站简介-为什么网站的ICO图标更新后,ie浏览器没有更新过来?

    为什么网站的ICO图标更新后,ie浏览器没有更新过来? 如何更新本地ico图标? 收藏夹里的网址访问后网站ico小图标怎么不会更新,还是没图标的. 如果制作了一个新的favicon.ico图标,并且已 ...

  4. RAC集群安装校验输出信息

    RAC集群安装校验输出信息 作者:Eric 微信:loveoracle11g [grid@rac-node1 grid]$ [grid@rac-node1 grid]$ ./runcluvfy.sh ...

  5. 5 Steps to Getting Started with SharePoint Development

    5 Steps to Getting Started with SharePoint Development Here are the steps I took to getting started ...

  6. samba安装

    第一步下载: wget https://download.samba.org/pub/samba/stable/samba-4.6.7.tar.gz 看了下没看到啥有用的直接安装: ./configu ...

  7. 百度UEditor粘贴或插入的表格不显示边框的解决办法

    原文链接:http://blog.csdn.net/lovelyelfpop/article/details/51678742 参考:https://www.cnblogs.com/xiangsj/p ...

  8. 字符串切分 String.Split 和 Regex.Split(小技巧)

    当切割字符串的是单个字符时可使用String.Split string strSample="ProductID:20150215,Categroy:Food,Price:15.00&quo ...

  9. 「2017 山东一轮集训 Day6」子序列(矩阵快速幂)

    /* 找出了一个dp式子 是否能够倍增优化 我推的矩阵不太一样 是 1 0 0 0 0 0 0 0 0 -1 0 0 1 0 0 0 0 0 1 0 0 1 0 0 2 求得逆矩阵大概就是 1 0 0 ...

  10. 关于js中的时间——计算时间差等

    获取当前(系统)时间: var NowDate= new Date(); // 获取当前日期时间 // 输出为: Wed May 03 2017 14:52:08 GMT+0800 (中国标准时间) ...