2011-07-25 45 views
6

Tôi đang cố gắng gọi một thủ tục được lưu trữ giữa python và một db oracle. Vấn đề tôi đang gặp phải là truyền tham số ngoài con trỏ.Python-Oracle Đi vào một tham số con trỏ ra

Thủ tục Oracle lưu trữ là chủ yếu:

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

    open ret for 
    select 
... 
    end; 

Mã python gọi đến cơ sở dữ liệu là:

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)) 

Lỗi này là:

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

Tôi cũng đã cố gắng chuyển từ điển dưới dạng từ khóaParameters:

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) 

Trả về cùng một lỗi.

Cảm ơn.

Trả lời

0

Hãy thử điều này:

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

Hi Scott, tôi quản lý để có được phương pháp callproc() để làm việc . Cảm ơn. – Jama

10

Sau một vài giờ googling và đường mòn/lỗi, đây là giải pháp:

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 
Các vấn đề liên quan