2011-07-25 28 views
6

Python ile bir oracle db arasında saklı bir yordamı çağırmaya çalışıyorum. Benim sahip olduğum problem bir imleç çıkış parametresini geçiyor.Python-Oracle Bir İmleç Çıkış Parametresinde Geçiş

Oracle saklı yordam temelde:

create or replace procedure sp_procedure(
    cid int, 
    rep_date date, 
    ret out sys_refcursor 
) is 
begin 

    open ret for 
    select 
... 
    end; 

veritabanına çağıran piton kodudur:

import cx_Oracle 
from datetime import date 

connstr='user/[email protected]:2521/XE' 
conn = cx_Oracle.connect(connstr) 
curs = conn.cursor() 

cid = 1 
rep_date = date(2011,06,30) 

curs.callproc('sp_procedure', (cid, rep_date, curs)) 

hatadır:

curs.callproc('sp_procedure', (cid, rep_date, curs)) 
cx_Oracle.DatabaseError: ORA-01036: illegal variable name/number 

Ben de denedim Bir sözlüğü anahtar sözcük olarak geçirmeParametreler:

cid = 1 
rep_date = date(2011,06,30) 

call_params = {'cid': cid, 'rep_date': rep_date, 'ret': curs} 
curs.callproc('sp_procedure', (cid, rep_date, curs), call_params) 

Aynı hatayı döndürür.

Teşekkürler.

cevap

0

bu deneyin:

curs = con.cursor() 
out_curs = con.cursor() 

curs.execute(""" 
BEGIN 
    sp_procedure(:cid, :rep_date, :cur); 
END;""", cid=cid, rep_date=rep_date, ret=outcurs) 
+0

Merhaba Scott, işe callproc() yöntemini başardı . Teşekkürler. – Jama

10

Googling ve iz/hatanın birkaç saat sonra burada çözüm:

cid = 1 
rep_date = date(2011,06,30) 

l_cur = curs.var(cx_Oracle.CURSOR) 
l_query = curs.callproc('sp_procedure', (cid,rep_date,l_cur)) 

l_results = l_query[2] 

for row in l_results: 
    print row 

# Column Specs 
for row in l_results.description: 
    print row