Reputation: 33
Given a PL/SQL procedure:
PROCEDURE MyProc(myvar IN sys.odcinumberlist, curout OUT sys_refcursor);
How do I execute it from python using cx_Oracle? I was trying
cursor.callproc('MyProc', (param, cursor_out))
with param being
[1, 2, 3]
or cursor.arrayvar(cx_Oracle.NUMBER, [1, 2, 3])
but it results in error 'wrong number or type of arguments'.
Upvotes: 3
Views: 316
Reputation: 31676
Use conn.gettype
to define the SYS.ODCINUMBERLIST
object. Then use it to assign a list of values (numbers)
Sample procedure
create or replace procedure MyProc( myvar IN sys.odcinumberlist,
curout OUT sys_refcursor )
AS
BEGIN
open curout for select * from TABLE(myvar);
END;
/
Python code
conn = cx_Oracle.connect('usr/pwd@//localhost:1521/DB')
cur = conn.cursor()
tableTypeObj = conn.gettype("SYS.ODCINUMBERLIST")
params = tableTypeObj.newobject()
po_cursor_out = cur.var(cx_Oracle.CURSOR)
params = tableTypeObj([1,2,3])
cur.callproc('hr.myproc', [ params, po_cursor_out])
result_cur = po_cursor_out.getvalue()
for row in result_cur:
print(row[0])
Result
1
2
3
Upvotes: 2