【发布时间】:2018-02-13 07:54:02
【问题描述】:
我正在对我用 Python 3.6 编写的 Oracle 11g 运行查询:
# running CP_ALL_PCK.get_pr
# open conncetion
con_get_pr = cx_Oracle.connect("****", "****", "****")
pr_cursor = con_get_pr.cursor()
# set parameters
pCurs = pr_cursor.var(cx_Oracle.CURSOR)
pRetCode = pr_cursor.var(cx_Oracle.NUMBER)
# run cursor
try:
pr_cursor.callproc('CP_ALL_PCK.get_pr',(pCurs,pRetCode))
except cx_Oracle.DatabaseError as exception:
print ('Failed to call procedure')
print (exception)
exit (1)
pr_cursor.fetchall()
res = pCurs.fetchall()
for row in res:
print(row)
pr_cursor.close()
con.close()
当我尝试使用 pCurs 光标时出现此错误:
pr_cursor.fetchall()
cx_Oracle.InterfaceError: not a query
如何使用和遍历这个光标?我在 cx_oracle 的文档中搜索了答案,但找不到任何关于迭代作为过程变量返回的游标的参考。
【问题讨论】:
-
你说 "this error" 但你没有告诉我们错误是什么。如果没有重要的线索,很难告诉你哪里出了问题。
-
删除
pr_cursor.fetchall()这一行,因为错误提示它不是查询 -
@Plirkee,但我如何通过 pCurs 进行迭代?我做错了吗?
-
@neoghost for
pCurs你得到了res = pCurs.fetchall()行,而不是pr_cursor没有什么可取的。
标签: python oracle python-3.x cursor