本文介绍了Python Oracle,插入None错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通过以下方式将None值插入oracle时出现错误:
I'm getting an error when inserting None values into oracle in the following way:
host = ('value1', 'value2', None, None)
sql_insert = "INSERT INTO sm9_data_hostname (field1, field2, field3, field4) VALUES ( :1, :2, :3, :4)"
conn_link.execute(sql_insert, host)
connection.commit()
错误是:cx_Oracle.DatabaseError:ORA-01036:非法的变量名称/编号
The error is:cx_Oracle.DatabaseError: ORA-01036: illegal variable name/number
如果我使用"Null"而不是"None",则插入有效.我看不到此查询有什么问题,因为参数应将Null替换为none.还是这是错误的假设?
The insert works if I use 'Null' instead of None.I can't see what's wrong with this query as the parameters should replace the none with a Null. Or is this the wrong assumption?
谢谢,以撒
推荐答案
我完全没有使用 cx_Oracle
的经验,但是我建议您尝试使用命名占位符作为替代方案.如以下
I have no experience at all with cx_Oracle
but I would suggest you try using named placeholders as an alternative. Such as the following
conn_link.execute(
"INSERT INTO sm9_data_hostname (field1, field2, field3, field4) "
"VALUES (:field1, :field2, :field3, :field4)",
dict(field1="value1", field2="value2", field3=None, field4=None)
)
这篇关于Python Oracle,插入None错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!