python执行oracle的insert命令

import random
import sys
import os
import cx_Oracle#可以用pip3 install cx_Oracle比网页下载更方便

db = cx_Oracle.connect('system','123456','192.168.56.2/orcl')#链接字符串 其中123456是密码
cr=db.cursor()#


def GBK2312():
    head = random.randint(0xb0, 0xf7)
    body = random.randint(0xa1, 0xf9)  
    val = f'{head:x}{body:x}'
    str = bytes.fromhex(val).decode('gb2312')
    return str

for i in range(0,500000):
    a=str("")
    b=GBK2312()
    for ia in range(0,8):
        a=a+random.choice('0123456789')
    for ib in range(0,2): 
        b=b+GBK2312()
    c=random.choice('01')
    d=str(random.randint(15, 25))
    e=str(random.choice('123456789'))
    f=str(random.choice('123456'))
    x="insert into  STUINFO values ('"+a+"','"+b+"','"+c+"','"+d+"','"+e+"','"+"','"+f+"')"#以上几行用于生成insert语句
    print(i)     
    cr.execute(x)#执行insert语句    
    db.commit()#提交数据,不提交就无用,数据不多时可执行多次insert再comm一次
cr.close()#关闭光标
db.close()#关闭数据库连接

 

posted on 2020-06-15 17:20  所有人都  阅读(1340)  评论(0)    收藏  举报

导航