我正在运行一个针对Oracle 11g的查询,我已经用Python 3.6编写了
# 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的文档中搜索了一个答案,但无法找到迭代通过从过程返回的游标的任何引用。
答案 0 :(得分:0)
我解决了!
# run cursor
try:
res = pr_cursor.callproc('<name of procedure>',[pCurs,pRetCode])[0]
except cx_Oracle.DatabaseError as exception:
print ('Failed to call procedure')
print (exception)
exit (1)
i=0
for line in res:
i=i+1
print ("{}) {}".format(i,line))
pr_cursor.close()
con.close()
我在最后错过了[0],表示我想要返回光标。 谢谢大家的帮助。
找到它here