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  

posted @ 2014-11-10 20:23  tom.sun  阅读(368)  评论(0编辑  收藏  举报