Python中带有Oracle存储过程的命名参数 [英] Named Parameters with a Oracle stored procedure in Python

查看:245
本文介绍了Python中带有Oracle存储过程的命名参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试调用现有存储过程,但使用命名参数时,第一个参数应保留默认值(在这种情况下为NULL).

Trying to call an existing stored procedure, but using named parameters, first parameter should retain default value (in this case NULL).

我花了很长时间试图使它生效,有什么想法吗?

I've spent way too long trying to get this working, any ideas?

create or replace procedure so_test(p1 in varchar2 default null, p2 in     varchar2  default null, p3 in varchar2  default null) as
begin
    null;
end;

import cx_Oracle
db = cx_Oracle.connect('/@XTS_DEV.CLIENT')
cur = db.cursor()
cur.callproc("so_test", ('X', 'Y', 'Z'))
cur.callproc("so_test(p2=>:1, p3=>:2)", ('Y', 'Z'))

Traceback (most recent call last):
  File "C:\Users\PatrickJolliffe\so_test.py", line 5, in <module>
    cur.callproc("so_test(p2=>:1, p3=>:2)", ('Y', 'Z'))
cx_Oracle.DatabaseError: ORA-06550: line 1, column 7:
PLS-00801: internal error [22503]
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

推荐答案

文档( http://cx-oracle.readthedocs.io/en/latest/cursor.html#Cursor.callproc )涵盖了这一点,但是由于这里没有提供示例,因此我可以看到令人困惑. :-)

The documentation (http://cx-oracle.readthedocs.io/en/latest/cursor.html#Cursor.callproc) covers this but since no examples are provided there I can see how that might be confusing. :-)

在您的示例中,这就是您想要的:

For your example, this is what you want:

cursor.callproc("so_test", keywordParameters = dict(p2 = "Y", p3 = "Z"))

这篇关于Python中带有Oracle存储过程的命名参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆