[英]Python cx_oracle insert error
我正在尝试使用python
脚本将csv
记录插入到oracle 11g
数据库中。
首先,应用程序成功插入了一些记录,但随后引发了此异常Error <class 'cx_Oracle.DatabaseError'>
。
def orcl_proc(sql):
# Open database connection
db = cx_Oracle.connect('username/password@localhost/XE')
# prepare a cursor object using cursor() method
cursor = db.cursor()
try:
# Execute the SQL command
cursor = cursor.execute(sql)
# Commit your changes in the database
db.commit()
except cx_Oracle.DatabaseError as e:
# Log error as appropriate
error, = e.args
print('Error.code =', error.code)
print('Error.message =', error.message)
print('Error.offset =', error.offset)
# Rollback in case there is any error
db.rollback()
# disconnect from server
db.close()
#print('Closed')
错误:
<class 'cx_Oracle.DatabaseError'>
在56367条记录中,python应用程序只能插入180条记录。 有人可以帮助我吗,谢谢。
从Python脚本中删除异常处理程序。 让Oracle数据库传播该错误,并查看其Oracle错误代码和消息文本,您将确切知道导致错误的原因。
然后,如果不确定这些含义是什么,请回到此处并发布Oracle的响应方式。
当与数据库的连接速率高于配置的DB的连接速率时,可能会出现间歇性的“ ORA-12516:TNS:侦听器找不到具有匹配协议栈的可用处理程序”。 尝试增加数据库的“ processes”参数。 如果您需要帮助,请参见免费的PDF http://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html中的“配置数据库以进行测试”部分
我实际上找到了答案。 感谢LittleFoot和Christopher Jones。 除去异常处理程序后,我得到了ORA-12516: TNS:listener could not find available handler with matching protocol stack
,我必须增加数据库进程和会话。
alter system set processes=1000 scope=spfile;
alter system set sessions=2248 scope=spfile;
startup
而且有效。 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.