我编写了以下函数来简化调用存储过程的方式。我需要有关如何返回out参数的帮助。
def call_procedure(dbname,procedure_name,parameters_list=[]):
with connections[dbname].cursor() as cursor:
try:
cursor.callproc(procedure_name, parameters_list)
except Exception as e:
raise Exception(e)
程序调用:
call_procedure('testdb',[1,2,3,''])
在通话中,我需要打印出参数。
Django在文档中缺少重要信息。
有关PL / SQL执行(Oracle DB)的详细说明,请检查cx_Oracle docs页面中的此链接
from django.db import connection
with connection.cursor() as cursor:
outVal = cursor.var(int).var
cursor.callproc('myproc', [123, outVal])
print(outVal.getvalue()) # will print 246
程序:
create or replace procedure myproc (
a_Value1 number,
a_Value2 out number
) as
begin
a_Value2 := a_Value1 * 2;
end;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句