如何扩展cx_oracle sys_refcursor Curor类

2024-04-24 08:22:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图扩展一个游标,它是在一个过程返回sys_refcursor时创建的。解决方案How to extend OracleCursor class from cx_Oracle适用于连接.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()

结果

^{pr2}$

有什么办法扩展这个光标吗?在


Tags: fromtestselfdefsysresultcursorclass