excutebatch()
功能
该函数用于执行批量操作,用法和 execute() 类似。
参数
- SQL语句。
- 各个参数的集合。
返回值
无。
使用说明
- 此函数允许执行批量操作。
- 在传入参数时,须保证各个参数列表(元组)的成员个数一致,否则会因异常退出。
代码示例
#!/usr/local/bin/python3
import os
import xgcondb
conn=xgcondb.connect(host="127.0.0.1",port="5138",database="PYTHON3",user="SYSDBA", password="SYSDBA")
cur=conn.cursor()
cur.execute("create table update_tab(d1 int,d2 varchar);")
t_list_1 = []
t_list_2 = []
name = 'Python'
for i in range(5000):
## 单次批量执行改变的行数不得超过数据库设置的单个事务最大变更数
t_list_1.append(i)
t_list_2.append(name+str(i))
cur.executebatch('insert into update_tab values(?,?);',(t_list_1,t_list_2))
cur.execute("select * from update_tab;")
row3=cur.fetchall()
print(row3)
cur.execute("drop table update_tab;")
cur.close()
conn.close()