python 读写Oracle10g数据简介
1、测试环境:
Centos6 X86_64
python 2.6
Oracle 10g
2、安装cx_Oracle 和 Oracle InstantClient:
http://www.rpmfind.net/linux/rpm2html/search.php?query=cx_oracle
http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
3、编辑当前用户的 .bash_profile, 在文件末尾增加下行:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/oracle/10.2.0.3/client64/lib
命令行执行 source .bash_profile
4、现在就可以用 python 脚本非常轻松的读写Oracle数据库
数据查询示范脚本 select_ora.py
# This script prints the data in Oracle Sample table scott.emp .
# Run with a parameter 'PageSize' in integer form, the output pauses at the end of every page.
# Run without a parameter or the parameter is not in integer form, the output doesn't pasue.
# Like:
# $ python select_ora.py 30
# $ python select_ora.py
#
import sys
import cx_Oracle
try:
intPageSize = int(sys.argv[1])
except:
intPageSize = -1
#print "Please input an integer."
#quit() conn = cx_Oracle.connect('scott/tiger@192.168.150.115/c6115')
cursor = conn.cursor ()
cursor.execute ("select * from emp")
print "EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO"
print "========================================================"
while (1):
row = cursor.fetchone()
if row == None: break
print "%d, %s, %s, %s, %s, %s, %s, %s" % (row[0], row[1], row[2], row[3], row[4],row[5],row[6],row[7])
if intPageSize <> -1 and cursor.rowcount % intPageSize == 0 :
strPress = raw_input( "Row: %d" % cursor.rowcount + ". Press Enter to continue, q to quit..." )
if strPress == 'q': break print "Number of rows returned: %d" % cursor.rowcount
cursor.close ()
conn.close ()
数据插入示范脚本 insert_ora.py
import cx_Oracle
startNum = raw_input("Start Num:")
endNum = raw_input("End Num:") conn = cx_Oracle.connect('scott/tiger@192.168.150.115/c6115')
cursor = conn.cursor()
i = int(startNum)
while (1):
i = i+1
if i > int(endNum):
break
theNum=str(i)
cursor.execute("insert into emp (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO) values("+theNum+",'FORD"+theNum+"','CLERK',7782,'09-JUN-81',2500,0,30)")
conn.commit()
print "Line "+ theNum +" inserted."
cursor.close()
conn.close()
参考: http://blog.csdn.net/kongxx/article/details/7107661
python 读写Oracle10g数据简介的更多相关文章
- python 读写json数据
json 模块提供了一种很简单的方式来编码和解码JSON 数据. 字符串操作 其中两个主要的函数是json.dumps() 和json.loads() ,要比其他序列化函数库如pickle 的接口少得 ...
- Python 读写excel数据
读取excel 文件的数据 import csv with open('D:/mystuff/11.csv','r') as f: reader = csv.reader(f) for row in ...
- python操作txt文件中数据教程[1]-使用python读写txt文件
python操作txt文件中数据教程[1]-使用python读写txt文件 觉得有用的话,欢迎一起讨论相互学习~Follow Me 原始txt文件 程序实现后结果 程序实现 filename = '. ...
- Python之读写文本数据
知识点不多 一:普通操作 # rt 模式的 open() 函数读取文本文件 # wt 模式的 open() 函数清除覆盖掉原文件,write新文件 # at 模式的 open() 函数添加write ...
- Python读写文件
Python读写文件1.open使用open打开文件后一定要记得调用文件对象的close()方法.比如可以用try/finally语句来确保最后能关闭文件. file_object = open('t ...
- python处理地理数据-geopandas和pyshp
这边博客并不是有关geopandas的教程和pyshp的教程! 使用python来处理地理数据有很多相关的包,最近研究需要处理一些地理数据,然而arcgis的arcpy总是不能令人满意.所以这里说说p ...
- Python 3.0(一) 简介
Python 3.0(一) 简介 [目录] 1.简介 2.python特点 3.安装 简介: Python是可以称得上即简单又功能强大的少有的语言中的一种.你将会惊喜地发现,专注于问题的解决方案而不是 ...
- python 读写、创建 文件
python中对文件.文件夹(文件操作函数)的操作需要涉及到os模块和shutil模块. 得到当前工作目录,即当前Python脚本工作的目录路径: os.getcwd() 返回指定目录下的所有文件和目 ...
- Linux就这个范儿 第15章 七种武器 linux 同步IO: sync、fsync与fdatasync Linux中的内存大页面huge page/large page David Cutler Linux读写内存数据的三种方式
Linux就这个范儿 第15章 七种武器 linux 同步IO: sync.fsync与fdatasync Linux中的内存大页面huge page/large page David Cut ...
随机推荐
- Centos7.4 更换国内yum源
1.进入yum源配置文件夹.(配置之前先看看有没有安装wget命令呢,没的话可以先用当前的yum源安装一下再说.yum -y install wget) 2.转到配置文件目录 cd /etc/yum ...
- phpmyadmin更改用户名和密码
我是用的xampp集成环境,wampp也差不多.另外没有配图,希望读者可以在实践的过程中有所思考,本文的主旨就是:找一个不叫root但和root一样厉害的人来管理数据库. 1,做个准备 首先创建一个和 ...
- bootstrap表单控件
禁用状态: 被禁用的 fieldset 为<fieldset> 设置 disabled 属性,可以禁用 <fieldset> 中包含的所有控件. <form> &l ...
- adminlte+layui框架搭建3 - layui弹出层
在amdinlte首页引入layui.js 和layui.css后添加代码 <script> layui.use(['layer'], function () { var layer = ...
- Qt 学习之路 2(71):线程简介
Qt 学习之路 2(71):线程简介 豆子 2013年11月18日 Qt 学习之路 2 30条评论 前面我们讨论了有关进程以及进程间通讯的相关问题,现在我们开始讨论线程.事实上,现代的程序中,使用线程 ...
- 【转】org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be res
如图所示: 看网上的解决方案,有的说是jstl的版本问题,1.0版本引入使用的时候加的uri不带有jsp路径的,1.2的带有/jsp路径,还有的说是依赖冲突的问题,最后尝试了都不行,只有一招能够行的通 ...
- 记一个SpringBoot中属性注入失败的问题Consider defining a bean of type ''' in your configuration
今天遇到的一个问题: 代码检查了好几次,都没有错误,但是启动时就会报错Consider defining a bean of type ''' in your configuration. 启动类在c ...
- tornado 09 cookie和session
tornado 09 cookie和session 一.cookie #有什么办法能够让浏览器记住登录信息,下次再打开的时候可以自动登录?网站是如何记录登录信息的? class SetCookieHa ...
- POJ1064 Cable master 【二分找最大值】
题目:题目太长了! https://vjudge.net/problem/POJ-1064 题意分析:给了你N根长度为小数形式的棍子,再给出了你需要分的棍子的数量K,但要求你这K根棍子的长度必须是一样 ...
- 浅谈C#数组(一)
如果需要使用同一类型的多个对象,可以使用数组和集合(后面介绍).C#用特殊的记号声明,初始化和使用数组.Array类在后台发挥作用,它为数组中的元素排序和过滤提供了多个方法.使用枚举器,可以迭代数组中 ...