早上好,
我试图找到一种方法来做一个插入到返回的SQL语句在Python中。我想使用executemmany,但我的代码在这一点上相当不可行。任何帮助将不胜感激。谢谢你。
下面是创建表的SQL:
CREATE TABLE TABLE1
( F1 NUMBER(*,0) GENERATED ALWAYS AS IDENTITY MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1,
F2 NUMBER(*,0) NOT NULL ENABLE,
CONSTRAINT "TABLE1_PK" PRIMARY KEY ("F1")
)
Python代码是:
import cx_Oracle
def makeCxDSNLessConnection(src):
return cx_Oracle.connect(user=sUser, password=sPass ,dsn=src)
def tempDoit():
oraCon = makeCxDSNLessConnection('EPAT')
cur = oraCon.cursor()
thislist=list()
thisOut = cur.var(int)
cur.execute("TRUNCATE TABLE TABLE1")
for i in range(1000000):
thislist.append((i,))
cur.executemany("INSERT INTO TABLE1(F2) VALUES(:1) RETURNING F1 INTO :2", thislist, thisOut )
oraCon.commit()
while True:
rows = cur.fetchmany(100)
if not rows:
break
for row in rows:
print(row)
1条答案
按热度按时间q1qsirdb1#
我找到了正确的Python代码: