Python cx_oracle插入错误

时间:2018-01-22 16:18:32

标签: python oracle oracle11g

我正在尝试使用csv脚本将oracle 11g中的记录插入python数据库。

主要是应用程序成功插入一些记录,但后来抛出此异常错误<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'>

在5667条记录中,python应用程序只能插入180条记录。请提前感谢任何身体帮助我。

3 个答案:

答案 0 :(得分:0)

从Python脚本中删除异常处理程序。让Oracle数据库传播它,你就会知道究竟是什么导致了错误,看到它的Oracle错误代码和消息文本。

然后,如果你不确定这些意思,请回到这里并发布Oracle如何回应。

答案 1 :(得分:0)

间歇性&#34; ORA-12516:TNS:侦听器找不到具有匹配协议栈的可用处理程序&#34;当与DB的连接速率高于DB配置为应对时,可能会发生这种情况。尝试碰撞过程&#39; DB的参数。如果您需要帮助,请参阅&#34;配置数据库以进行测试&#34;在免费的PDF http://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html

答案 2 :(得分:0)

我实际上找到了答案。感谢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

它有效。 感谢

相关问题