Named Parameters with a Oracle stored procedure in Python

为君一笑 提交于 2019-12-22 12:45:07

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/40586019/named-parameters-with-a-oracle-stored-procedure-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!