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

 

posted @ 2018-12-14 21:45  onelang  阅读(6045)  评论(0编辑  收藏  举报