python如何操作oracle数据库_python操作oracle数据库
搜索热词
下面是编程之家 jb51.cc 通过网络收集整理的代码片段。
编程之家小编现在分享给大家,也给大家做个参考。
# -*- 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/[email protected]/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'],'unique_code255','group_code255','debug255','33333333344'],'unique_code266','group_code266','debug266','44444444455'],'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'],'48'],'34']]
pythonOralceUtil.updateManay(updateValues)
pythonOralceUtil.queryAll()
pythonOralceUtil.queryBySeq([27])
以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。
相关文章
总结
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您喜欢交流学习经验,点击链接加入交流1群:1065694478(已满)交流2群:163560250
python如何操作oracle数据库_python操作oracle数据库相关推荐
- python查询oracle数据库_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 解释器所在的目 ...
- python读取oracle数据库数据库_Python读写Oracle数据库
最近项目中需要用到Python调用Oracle实现读写操作,踩过很多坑,历尽艰辛终于实现了.性能怎样先不说,有方法后面再调优嘛.现在把代码和注意点记录一下. 1. 所需Python工具库 cx_Ora ...
- 用python向mongodb插入数据_Python操作MongoDB数据库(一)
Python操作MongoDB数据库(一) 前言 干货文章继续出发!隔的时间有些久了哈,对 MongoDB 安装回顾的同学,可以看下windows环境 <初识 MongoDB 数据库>.这 ...
- python的sqlite数据库_Python操作SQLite数据库
### 连接数据库 从2.5版本开始,Python的标准库中就有了一个专门用于SQLite的sqlite3模块.连接SQLite数据库方式如下: ~~~ import sqlite3 as dbapi ...
- mysql访问oracle数据_python访问Oracle及Mysql数据库
# !/usr/local/python # -*- coding: utf-8 -*- import cx_Oracle import pymysql # --------oracle链接数据库-- ...
- python操作mongodb语法_python 操作MongoDB
安装MongoDB 启动数据库:安装完成指定数据库存放路径 mongod.exe --dbpath c:\data\db 进入目录后运行mongo.exe 成功 创建数据库 >use mydb ...
- python操作mongodb语法_python操作mongodb怎么找到所有的集合
{"moduleinfo":{"card_count":[{"count_phone":1,"count":1}],&q ...
- python对excel操作简书_Python 操作Excel
操作Excel的Python模块有很多,从操作难易度和功能两方面考虑,选择了下面两个模块. 1. 读Excel模块 xlrd API reference xlrd提供了按行读取和按单元格读取两种方式 ...
- python自带的数据库_Python小白的数据库入门
前言 SQL数据库数据库SQL语言入门SQL简介SQL 的作用 SQL语句分类 SQLite 数据库SQLite 中的数据类型 DDL语句创建表 删除表 修改表 DML语句添加 删除 修改 查询 Py ...
最新文章
- V2X 是自动驾驶重要基石,巨头纷纷抢滩布局
- 第一家科创板IPO的AI公司:年净利1.58亿,华为小米背后功臣,北大物理系校友创办...
- Android Cursor自动更新的实现和原理
- 枚举--遍历搜索空间的例子:熄灯问题
- python jdbc_javapython连接mysql快速造数
- 对《程序员的自我修养》(龙书)读后思考
- 本地构建和自动化构建_构建自动化面板
- 前端解读面向切面编程(AOP)
- mysql常用四种连接_MySQL四种连接查询
- 【转】Android 中的 Service 全面总结
- 实体首部字段-四大首部字段之一
- Palindrome Number
- 如何格式化搭载 Apple 芯片的 Mac?
- 夜间灯光数据下载(DMSP/OLS,NPP/VIIRS、珞珈一号网址)
- 德国铁路公司基于模型的铁路系统设计路线图 - 基于模型的系统开发在铁路部门的应用
- matlab 2016b caffe,请教:在Win7+VS 2013+Matlab R2016b上编译Caffe时遇到问题
- 易基因 - 外泌体let-7d-3p和miR-30d-5p作为宫颈癌及其癌前病变无创筛查的诊断标志物|早期筛查
- 台式计算机亮度设置,怎么调台式电脑亮度_怎么调台式电脑的亮度
- Servlet内存马
- python编写一个汽车类_编写类-汽车类
热门文章
- python扩展文件_1. 使用 C 或 C++ 扩展 Python
- (1)《Head First HTML与CSS》学习笔记---HTML基本概念
- vue.extend与vue.component的区别和联系
- 4、Node.js REPL(交互式解释器)
- jQuery源码的基础知识
- 启动LINUX下的TFTP服务器
- 使用echarts时,鼠标首次移入屏幕会闪动,屏幕会出现滚动条
- mac中apache服务器及虚拟主机配置
- fit_transform和transform的区别
- 反射例子(配置文件)