python oracle 查询返回字典
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 查询返回字典的更多相关文章
- python mysql 查询返回字典结构
cur = self.conn.cursor(MySQLdb.cursors.DictCursor)加上MySQLdb.cursors.DictCursor可以返回字典结构 {列名:值} class ...
- 让 Python 的1、数据库查询返回字典记录--- 2、利用zip函数将两个列表(list)组成字典(dict)
让 Python 的数据库查询返回字典记录: https://yanbin.blog/python-database-query-return-dictionary-result/#more-9179 ...
- python调用数据返回字典dict数据的现象2
python调用数据返回字典dict数据的现象2 思考: 话题1连接:https://www.cnblogs.com/zwgbk/p/10248479.html在打印和添加时候加上内存地址id(),可 ...
- python调用数据返回字典dict数据的现象1
python调用数据返回字典dict数据的现象1 思考: 可以看到这两种情况,区别在于构造函数make()里赋值给字典dict的方式不同.使用相同的调用方式,而结果却完全不同.可以看到第二种情况才是我 ...
- 18.Django原生SQL语句查询返回字典
在django中执行自定义语句的时候,返回的结果是一个tuple ,并我不是我所期望的dict.当结果是tuple 时,如果要取得数据,必须知道对应数据在结果集中的序号,用序号的方式去得到值. 如果是 ...
- Python查询Mysql时返回字典结构的代码
Python查询Mysql时返回字典结构的代码 MySQLdb默认查询结果都是返回tuple,输出时候不是很方便,必须按照0,1这样读取,无意中在网上找到简单的修改方法,就是传递一个cursors.D ...
- Python中让MySQL查询结果返回字典类型的方法
import pymysql host='localhost' user='root' passwd='root' port=3306 db='test' db=pymysql.connect( ho ...
- django原生sql查询如何返回字典格式
django原生sql查询,默认返回的是元祖.如果想返回字典格式,需要自行封装: http://www.360doc.com/content/17/0802/11/9200790_676042880. ...
- oracle[insert 时报错: 单行子查询返回多行]
-- 错误的写法 insert into t_b_partner_vehicle(id, partner_id, vehicle_id) (seq_t_b_partner_vehicle.nextva ...
随机推荐
- mysql 5.6 binlog组提交实现原理(转载)
http://blog.itpub.net/15480802/viewspace-1411356/ Redo组提交 Redo提交流程大致如下 lock log->mutex write redo ...
- centos6.5虚拟机快照技术
一.查看现有磁盘镜像格式与转换 查看磁盘格式 [root@localhost ~]# qemu-img info /var/lib/libvirt/images/centos7.img image: ...
- android-sdk和api版本
Platform Version API Level VERSION_CODE Notes Android 8.1 27 O_MR1 平台亮点Android 8.0 26 O 平台亮点An ...
- git之win安装git和环境配置及常用命令总结
12.windowns安装git和环境变量配置 11.git之常见命令总结 ===== 12.windowns安装git和环境变量配置 ; 转自 https://wuzhuti.cn/2385.htm ...
- MySQL 之数据库增量数据恢复案例
MySQL 数据库增量数据恢复案例 一.场景概述 MySQL数据库每日零点自动全备 某天上午10点,小明莫名其妙地drop了一个数据库 我们需要通过全备的数据文件,以及增量的binlog文件进行数据恢 ...
- Python 画3D图像
绘制一副3D图像 draw3D(X,Y,Z, angle) import numpy as np from matplotlib import pyplot as plt from mpl_toolk ...
- unity3d动态创建一个文本
2D文本需要Canvas和EventSystem,最好使用Editor来添加: 动态显示一个文本,采用3D Text的方式: GameObject text = new GameObject(); t ...
- 字符串切分 String.Split 和 Regex.Split(小技巧)
当切割字符串的是单个字符时可使用String.Split string strSample="ProductID:20150215,Categroy:Food,Price:15.00&quo ...
- vue2.0 slot用法
学习vue.js也有一段时间了,关于slot这一块,也看了不少次了,总感觉有点迷迷糊糊,不知其然也不知其所以然,抽出一段完整的时间,再一次仔细学习.稍微有点理解了,在此稍作记录,好记性不如烂笔头嘛! ...
- Error: 实例 "ddd" 执行所请求操作失败,实例处于错误状态。: 请稍后再试 [错误: Exceeded maximum number of retries. Exhausted all hosts available for retrying build failures for instance 6f60bc06-fcb6-4758-a46f-22120ca35a71.].
Error: 实例 "ddd" 执行所请求操作失败,实例处于错误状态.: 请稍后再试 [错误: Exceeded maximum number of retries. Exhaus ...