Reputation: 31
I am trying to call a oracle stored procedure with 2 in and 1 out parameter from python script. The problem I am having is passing a cursor out-parameter.
The Oracle stored procedure is essentially:
PROCEDURE ci_lac_state
(LAC_ID_IN IN VARCHAR2,
CI_ID_IN IN VARCHAR2 DEFAULT NULL,
CGI_ID OUT SYS_REFCURSOR)
AS
BEGIN
OPEN cgi_id FOR
...
END;
The python code calling to the database is:
#! /usr/bin/python
import cx_Oracle
lac='11508'
ci='9312'
try:
my_connection=cx_Oracle.Connection('login/passwd@db_name')
except cx_Oracle.DatabaseError,info:
print "Logon Error:",info
sys.exit()
my_cursor=my_connection.cursor()
cur_var=my_cursor.var(cx_Oracle.CURSOR)
my_cursor.callproc("cgi_info.ci_lac_state", [lac, ci, cur_var])
print cur_var.getvalue()
And I get such cursor value as the result:
<__builtin__.OracleCursor on <cx_Oracle.Connection to login@db_name>>
What am I doing wrong?
Thanks.
Upvotes: 3
Views: 19765
Reputation: 139
You can define your output and then loop through using an implicit cursor like this:
outVal = cursor.var(cx_Oracle.CURSOR)
something = cursor.callproc(<your procedure name>, [outVal,<input variable here>])
for implicitCursor in cursor.getimplicitresults():
for row in implicitCursor:
fout.write(''.join(row)) # note: tuple conversion inside ()
fout.write('\n')
Upvotes: 0
Reputation: 1270
I've just had similar issue. cur_var
has type <type 'cx_Oracle.CURSOR'>
and cur_var.getvalue()
gets object of type <type 'OracleCursor'>
. To get data you have to fetched them from the OracleCursor object. Try for example:
print cur_var.getvalue().fetchall()
To see more function of OracleCursor object just check its directory:
dir(cur_var.getvalue())
Hope this will help you!
Upvotes: 1