我试图将PL/SQL记录参数传递给存储过程。我使用的是cx®Oracle 6.0b1。从cxu-Oracle文档中,我相信以下代码是正确的,但是,它总是导致错误PLS-00306: wrong number or types of arguments in call to 'CREATE_VENDOR'
我的代码:import cx_Oracle
ID_MAX_LEN = 29
def get_obj_of_type(type_name, connection):
type_name = type_name.replace('.', '_')[:ID_MAX_LEN]
typeObj = connection.gettype(type_name)
return typeObj.newobject()
def main():
dsn = {...}
connection = cx_Oracle.connect(dsn['user'], dsn['password'], dsn=dsn['oracle_dsn'])
cursor = connection.cursor()
try:
rec = get_obj_of_type('AP_VENDOR_PUB_PKG.R_VENDOR_REC_TYPE', connection)
rec.VENDOR_NAME = 'Test Vendor'
P_API_VERSION = 1.0
P_INIT_MSG_LIST = "T"
P_COMMIT = "T"
P_VALIDATION_LEVEL = 1
X_RETURN_STATUS = cursor.var(cx_Oracle.STRING)
X_MSG_COUNT = cursor.var(cx_Oracle.NUMBER)
X_MSG_DATA = cursor.var(cx_Oracle.STRING)
P_VENDOR_REC = rec
X_VENDOR_ID = cursor.var(cx_Oracle.NUMBER)
X_PARTY_ID = cursor.var(cx_Oracle.NUMBER)
result = cursor.callproc('AP_VENDOR_PUB_PKG.CREATE_VENDOR',
parameters=[P_API_VERSION,
P_INIT_MSG_LIST,
P_COMMIT,
P_VALIDATION_LEVEL,
X_RETURN_STATUS,
X_MSG_COUNT,
X_MSG_DATA,
P_VENDOR_REC,
X_VENDOR_ID,
X_PARTY_ID])
finally:
cursor.close()
connection.close()
main()
此存储过程是Oracle r12电子商务套件的一部分。如果您有权访问该产品的数据库实例,则此存储过程应该可用。在
安东尼要求的记录定义:
^{pr2}$
编辑:按照安东尼的建议,我试着用我自己创作的唱片:create or replace package XX_SUPPLIERS_PKG is
TYPE rec_test IS RECORD(p1 varchar2(255), p2 varchar2(255));
procedure test_record(p_rec in rec_test,
x_vendor out SYS_REFCURSOR);
[...]
end XX_SUPPLIERS_PKG;
当我尝试使用此存储过程并在cx\U Oracle中进行记录时,我得到:cx_Oracle.DatabaseError: ORA-04043: object XX_SUPPLIERS_PKG_REC_TEST does not exist
我检查了oraclesqldeveloper的DBA_TYPES视图,没有看到任何以“XX”或“REC”开头的类型
以下是产生上述错误的代码:import cx_Oracle
def main():
connection = cx_Oracle.connect(...)
cursor = connection.cursor()
try:
rec = connection.gettype('XX_SUPPLIERS_PKG_REC_TEST')
rec.P1 = "test"
rec.P2 = "test"
out_cursor = connection.cursor()
result = cursor.callproc('XX_SUPPLIERS_PKG.TEST_RECORD',
parameters=[rec, out_cursor])
finally:
cursor.close()
connection.close()
main()
另一个注意事项:我尝试使用在DBA_TYPES视图中可见的PL/SQL记录类型。这会导致类似的错误:cx_Oracle.DatabaseError: ORA-04043: object PL/SQL RECORD does not exist