python 连接oracle 数据库

我们在测试中可能需要对oracle 数据库进行操纵,比如这样一个场景,在往oracle 里面插数据的同时,另一个工具从里面读,如何能保证读出来的数据是有顺序的,即:先插入进去的先读出来,根据这个场景们首先需要制作一个不断往oracle 数据库里面插入数据的脚本。这个时候我们想到了python 的cx_Oracle库,下面我们就来实现一下:

import cx_Oracle
import time
ISOTIMEFORMAT='%Y-%m-%d %X'
def connectOracle():
conn=cx_Oracle.connect('dwa/dwa@10.32.164.119:1521/orcl')
cursor=conn.cursor()
cursor.execute("drop table test_increase")
cursor.execute("create table test_increase ( f1 CHAR(256) )")
cursor.execute("commit");
for i in range(0,999999):
c_time=time.strftime( ISOTIMEFORMAT, time.localtime( time.time() ) )
cursor.execute("insert into dt_test_increase values ('%d')" % (i) )
cursor.execute('commit')
print "%d,%s" % (i,c_time)
cursor.close()
conn.close()
if __name =='__main__':
connectOracle()

更多资料关注:www.kootest.com ;技术交流群:182526995  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值