# -*- mode: python; coding: utf-8 -*-

#

# python operate oracle, contain insert、delete、update、select.

#

# @author liyulin

# @date 2014-11-07

import cx_Oracle

class PythonOralceUtil:

def __enter__(self):

self.conn = cx_Oracle.connect('testuser/testpwd@localhost/CHROMEBOOK')

self.cursor = self.conn.cursor()

return self

def __exit__(self, type, value, traceback):

self.cursor.close()

self.conn.close()

############################################

# 查询reg_codes中的所有数据

############################################

def queryAll(self):

self.cursor.execute('select * from reg_codes')

results = self.cursor.fetchall()

for result in results:

print result

############################################

# 根据序号查询reg_codes中的一条数据

############################################

def queryBySeq(self, seq):

self.cursor.execute('select * from reg_codes where seq=:1', seq)

result = self.cursor.fetchone()

if (result is not None):

for index in range(0,6):

print result[index],

############################################

# 向reg_codes中插入N条数据

############################################

def insertManay(self, insertValue):

self.conn.begin()

try:

self.cursor.executemany('insert into reg_codes(device,unique_code,group_code,input_file,sn,input_ts) values(:1,:2,:3,:4,:5,sysdate)', insertValue)

except AssertionError:

self.conn.rollback()

raise Warning, "invalid insertValue (%s)" % insertValue

self.conn.commit()

############################################

# 更新reg_codes中一条数据

############################################

def updateOne(self, sqe, input_file):

updateValue = [input_file, sqe]

self.cursor.execute('update reg_codes set input_file=:1 where seq=:2', updateValue)

############################################

# 更新reg_codes中N条数据

############################################

def updateManay(self, updateValues):

self.conn.begin()

try:

self.cursor.executemany('update reg_codes set input_file=:1 where seq=:2', updateValues)

except AssertionError:

self.conn.rollback()

raise Warning, "invalid insertValue (%s)" % updateValues

self.conn.commit()

############################################

# 删除reg_codes中一条数据

############################################

def delete(self, sqe):

self.cursor.execute('delete from reg_codes where seq=:1', sqe)

############################################

# 删除reg_codes中N条数据

############################################

def deleteManay(self, seqs):

self.conn.begin()

try:

self.cursor.executemany('delete from reg_codes where seq=:1', seqs)

except AssertionError:

self.conn.rollback()

raise Warning, "invalid seqs (%s)" % seqs

self.conn.commit()

############################################

# 执行代码

############################################

with PythonOralceUtil() as pythonOralceUtil:

# insertValue = [['jerry', 'unique_code2333', 'group_code2333', 'debug233', '1111111111122'],

# ['jerry', 'unique_code244', 'group_code244', 'debug244', '22222222233'],

# ['jerry', 'unique_code255', 'group_code255', 'debug255', '33333333344'],

# ['jerry', 'unique_code266', 'group_code266', 'debug266', '44444444455'],

# ['jerry', 'unique_code277', 'group_code277', 'debug277', '55555555566']]

# pythonOralceUtil.insertManay(insertValue)

# pythonOralceUtil.updateOne('27', 'debug_updated')

# pythonOralceUtil.delete([27])

# pythonOralceUtil.deleteManay([[31],[44],[45]])

updateValues = [['debug_updated', '46'],

['debug_updated', '47'],

['debug_updated', '48'],

['debug_updated', '34']]

pythonOralceUtil.updateManay(updateValues)

pythonOralceUtil.queryAll()

pythonOralceUtil.queryBySeq([27])、

python调用oracle数据库_python操作oracle数据库相关推荐

  1. python如何操作oracle数据库_Python 操作 Oracle 数据库

    前言 操作系统:Window 10 64 位 RPA: IS-RPA 2020.2.0 查看 IS-RPA Python 版本 由下图可知: IS-RPA 安装在 E 盘,Python 解释器所在的目 ...

  2. python的sqlite数据库_Python操作SQLite数据库

    ### 连接数据库 从2.5版本开始,Python的标准库中就有了一个专门用于SQLite的sqlite3模块.连接SQLite数据库方式如下: ~~~ import sqlite3 as dbapi ...

  3. python连接数据库的技术_Python操作MySQL数据库的三种方法

    (1) 什么是MySQLdb? MySQLdb 是用于 Python 连接 MySQL 数据库的接口,它实现了 Python 数据库 API 规范 V2.0,基于 MySQL C API 上建立的. ...

  4. python不可以操作access数据库_Python操作Access数据库基本操作步骤分析

    Python编程语言的出现,带给开发人员非常大的好处.我们可以利用这样一款功能强大的面向对象开源语言来轻松的实现许多特定功能需求.比如Python操作Access数据库的功能实现等等.在Python操 ...

  5. python读取mysql数据库_Python操作MySQL数据库9个实用实例

    在Windows平台上安装mysql模块用于Python开发 用python连接mysql的时候,需要用的安装版本,源码版本容易有错误提示.下边是打包了32与64版本. MySQL-python-1. ...

  6. python调用mysql数据_python使用mysql数据库(虫师)

    转自虫师 http://www.cnblogs.com/fnng/p/3565912.html 一,安装mysql 如果是windows 用户,mysql 的安装非常简单,直接下载安装文件,双击安装文 ...

  7. python操作sqlite数据库_Python 操作SQLite数据库的示例

    SQLite,是一款轻型的数据库,是遵守ACID的关系型数据库管理系统,它包含在一个相对小的C库中.在很多嵌入式产品中使用了它,它占用资源非常的低,python 中默认继承了操作此款数据库的引擎 sq ...

  8. python如何操作oracle数据库_python操作oracle数据库

    搜索热词 下面是编程之家 jb51.cc 通过网络收集整理的代码片段. 编程之家小编现在分享给大家,也给大家做个参考. # -*- mode: python; coding: utf-8 -*- # ...

  9. python 测试mysql数据库_Python操作MySQL数据库----继续安装和测试

    接上篇,在上一篇中,我们安装好了python和sublime,下面我们需要安装MYSQL的相关软件. 1.安装MYSQL SERVER5.5.28,安装5.6版本的也可以,只是5.6版本安装完成之后没 ...

最新文章

  1. FortiGate基本信息
  2. 调用函数,计算分段函数的值
  3. 前端学习(1692):前端系列javascript之typeof
  4. P2249 【深基13.例1】查找(AC) 2022.1.28
  5. 数据科学家:我的工作就是发现别人未知的
  6. EXCEL 两列名字 如何快速查看缺少了哪些人名
  7. 光引发剂主要用途_光引发剂分类及用途
  8. Android中设置显示文本,TextView控件的使用(Android设置文本显示格式)
  9. 国内外有哪些有前景的 AR VR公司?
  10. 计算机硬件工程师需要学哪些,硬件工程师需要学习哪些知识 上EDA365电子论坛...
  11. PHP 引用在线编辑器,kindeditor
  12. 加拿大大学商用计算机专业,加拿大大学计算机专业排名一览
  13. 解决word、typora等打不开超链接问题
  14. 交换机 路由器模拟仿真软件命令
  15. Vue-实现商品放大镜效果
  16. Java——腐烂的橘子
  17. 哪个软件能代替斐讯路由_斐讯路由(老版本无需登录)
  18. photoshop将图层导出到文件脚本不带数字序号、下划线方法
  19. 《Java并发编程的艺术》读后笔记-Java中的并发工具类(第八章)
  20. 终年32岁的传奇数学家,生前寂寂无闻,一个世纪后却让硅谷领袖们集体落泪致敬

热门文章

  1. 四种ASP网页跳转代码
  2. 【STL源码剖析读书笔记】【第5章】关联式容器之set、map、multiset和multimap
  3. sum() over() 函数的使用
  4. 文档null一段 虚拟机操作
  5. com.microsoft.sqlserver.jdbc.SQLServerException: 索引 1 超出范围
  6. 微软一站式示例代码库 7月新代码示例发布
  7. /bin/sh^M:损坏的解释器: No such file or directory
  8. c语言编程基本概念,读朱兆祺攻破C语言之一----编程基本概念
  9. EOS 源代码解读 (2)插件-插件模板
  10. Kubernetes存储之PV-PVC