1. 程式人生 > >python呼叫oracle儲存過程

python呼叫oracle儲存過程

# -*- coding: utf-8 -*-
import cx_Oracle
conn = cx_Oracle.connect('user','pwd','tns')
cursor = conn.cursor()

#宣告變數
#呼叫儲存過程
sql = '''
    declare result boolean;
    begin
        result := cmx_target_sql.test(o_error_message =>:o_error_message);
        :result := sys.diutil.bool_to_int(result);
    end;

'''
result= cursor.var(cx_Oracle.NUMBER) 
msg=cursor.var(cx_Oracle.STRING)
args = [msg,result]
kwArgs = {}
re = cursor.execute(sql, args, **kwArgs)
conn.commit()
print(result.getvalue())
print(msg.getvalue())
cursor.close()
conn.close()