我试图扩展一个过程返回sys_refcursor时创建的游标。解决方案How to extend OracleCursor class from cx_Oracle适用于connection.cursor(),但不适用于sys_refcursor。
import cx_Oracle as cxo
class MyCursor(cxo.Cursor):
def helloWorld(self):
print "helloWorld"
class MyConnection(cxo.Connection):
def cursor(self):
return MyCursor(self)
if __name__ == '__main__':
conStr = 'ants/<password>'
db = MyConnection(conStr)
c = db.cursor()
c.execute("""
create or replace procedure cx_test_cursor(
val4 out sys_refcursor
) is
begin
open val4 for
select 1 a from dual union all
select 2 from dual;
end;
""")
result = c.callproc('ants.cx_test_cursor', [c.var(cxo.CURSOR)])
c.execute('drop procedure cx_test_cursor')
print result
result[0].helloWorld()
结果
[<cx_Oracle.Cursor on <__main__.MyConnection to user ants@local>>]
Traceback (most recent call last):
File "cx_test2.py", line 32, in <module>
result[0].helloWorld()
AttributeError: 'cx_Oracle.Cursor' object has no attribute 'helloWorld'
如何扩展此游标的任何想法?
答案 0 :(得分:0)
只有cx_Oracle 6及更高版本才能实现这一点。