python 调用Oracle有返回参数的存储过程
1. 存储过程
create or replace procedure pro_test_args(a in integer,b in integer, c out integer) is
beginc:= a * b ;end pro_test_args;
2. Python调用存储过程
import cx_Oracle
import os
import sys# 连接数据库
#conn = cx_Oracle.connect('username/password@host:port/service_name')
# 以下全局数据库变量
os.environ["ORACLE_HOME"] = '/app/oracle/product/12.2.0/db_home'
os.environ["LD_LIBRARY_PATH"] = '/app/oracle/product/12.2.0/db_home'db = cx_Oracle.connect('scott', 'Tiger', '127.0.0.1:1521/orcl')
# 创建游标
cursor = db.cursor()# 准备调用存储过程的参数
param1 = 3
param2 = 4
out_param = 0# 调用存储过程
result = cursor.callproc('pro_test_args', [param1, param2, out_param])# 关闭游标和数据库连接
cursor.close()
db.close()# 输出返回参数的值
print(result)
print(result[2])print(out_param)
执行结果:
[3, 4, 12]
12
0