Return A Stored Procedure Out Cursor Variable In Cx_oracle
I am trying to return a refcursor from a procedure in python using cx_oracle, my procedure looks something like the one below. below the procedure is the python that I am trying to
Solution 1:
The call to a procedure takes a sequence as parameter, and returns a sequence too.
l_test = self.__cursor.callproc("prc_get_some_data",[l_cur])
print(type(l_test))
#>>> <class 'list'>
So you can access the returned cursor by index :
ret_cursor = self.__cursor.callproc("prc_get_some_data",[l_cur])[0]
or
l_test = self.__cursor.callproc("prc_get_some_data",[l_cur])
ret_cursor = l_test[0]
Then you can print the result with a for loop
for line in ret_cursor:
print line
or with print ret_cursor.fetchall()
, or with the pprint
tool if needed.
In the documentation you've linked, the return value is directly unpacked to l_query
and l_emp
:
l_query, l_emp = self.__cursor.callproc("PKG_HR.FIND_EMPLOYEES", [p_query, l_cur])
By the way, you may need to close the returned cursor at the end, with the same method as the main cursor : ret_cursor.close()
. Otherwise it can throw an exception about the connection cannot be closed .
Post a Comment for "Return A Stored Procedure Out Cursor Variable In Cx_oracle"