简体   繁体   English

cx_Oracle - “期望 None 或字符串”

[英]cx_Oracle - "expecting None or a string"

I am on the following cx_Oracle version我在以下 cx_Oracle 版本

>>> cx_Oracle.version
'5.0.3'

I am getting this exception in executing a query我在执行查询时遇到此异常

"expecting None or a string" “期望 None 或字符串”

The query is being executed this way查询正在以这种方式执行

cursor.execute("SELECT * FROM APP_STORE WHERE STORE=:STORE %s" %(order_clause),{'STORE':STORE})

What could be the reason?可能是什么原因? Similar queries executed earlier in the flow work fine but this one does not.在流程中之前执行的类似查询工作正常,但这个查询不行。

Appreciate some guidance on this.欣赏这方面的一些指导。

You are building your cursor incorrectly.您正在错误地构建光标。 Since you pass a dictionary, you much first prepare your query:由于您传递了字典,因此您首先要准备查询:

cursor.prepare("SELECT * FROM APP_STORE WHERE STORE=:STORE %s" %(order_clause))

Then you execute it and pass None as the first parameter.然后你执行它并传递None作为第一个参数。

results = cursor.execute(None, {'STORE':STORE})

If you wish to change the STORE parameter and run the query again, all you need to do now is modify the dictionary and rerun the execute statement.如果您希望更改STORE参数并再次运行查询,您现在需要做的就是修改字典并重新运行execute语句。 prepare ing it again is not needed.不需要再次prepare

More information can be found at the Oracle+Python Querying best practices documentation .更多信息可以在Oracle+Python 查询最佳实践文档中找到 The information I provided, above, is in the "Bind Variable Patterns" section (no direct link seems to be available)我在上面提供的信息在“绑定变量模式”部分(似乎没有直接链接可用)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM