我正在尝试将 PL/SQL 记录参数传递给存储过程。我正在使用 cx_Oracle 6.0b1。从 cx_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 E-Business Suite 的一部分。如果您有权访问该产品的数据库实例,则该存储过程应该可用。
Anthony 要求的记录定义:
TYPE r_vendor_rec_type IS RECORD(
VENDOR_ID NUMBER,
SEGMENT1 AP_SUPPLIERS.SEGMENT1%TYPE,
VENDOR_NAME AP_SUPPLIERS.VENDOR_NAME%TYPE,
VENDOR_NAME_ALT AP_SUPPLIERS.VENDOR_NAME_ALT%TYPE,
SUMMARY_FLAG AP_SUPPLIERS.SUMMARY_FLAG%TYPE,
ENABLED_FLAG AP_SUPPLIERS.ENABLED_FLAG%TYPE,
SEGMENT2 AP_SUPPLIERS.SEGMENT2%TYPE,
SEGMENT3 AP_SUPPLIERS.SEGMENT3%TYPE,
SEGMENT4 AP_SUPPLIERS.SEGMENT4%TYPE,
SEGMENT5 AP_SUPPLIERS.SEGMENT5%TYPE,
EMPLOYEE_ID NUMBER,
VENDOR_TYPE_LOOKUP_CODE AP_SUPPLIERS.VENDOR_TYPE_LOOKUP_CODE%TYPE,
CUSTOMER_NUM AP_SUPPLIERS.CUSTOMER_NUM%TYPE,
ONE_TIME_FLAG AP_SUPPLIERS.ONE_TIME_FLAG%TYPE,
PARENT_VENDOR_ID NUMBER,
MIN_ORDER_AMOUNT NUMBER,
TERMS_ID NUMBER,
SET_OF_BOOKS_ID NUMBER,
ALWAYS_TAKE_DISC_FLAG AP_SUPPLIERS.ALWAYS_TAKE_DISC_FLAG%TYPE,
PAY_DATE_BASIS_LOOKUP_CODE AP_SUPPLIERS.PAY_DATE_BASIS_LOOKUP_CODE%TYPE,
PAY_GROUP_LOOKUP_CODE AP_SUPPLIERS.PAY_GROUP_LOOKUP_CODE%TYPE,
PAYMENT_PRIORITY NUMBER,
INVOICE_CURRENCY_CODE AP_SUPPLIERS.INVOICE_CURRENCY_CODE%TYPE,
PAYMENT_CURRENCY_CODE AP_SUPPLIERS.PAYMENT_CURRENCY_CODE%TYPE,
INVOICE_AMOUNT_LIMIT NUMBER,
HOLD_ALL_PAYMENTS_FLAG AP_SUPPLIERS.HOLD_ALL_PAYMENTS_FLAG%TYPE,
HOLD_FUTURE_PAYMENTS_FLAG AP_SUPPLIERS.HOLD_FUTURE_PAYMENTS_FLAG%TYPE,
HOLD_REASON AP_SUPPLIERS.HOLD_REASON%TYPE,
TYPE_1099 AP_SUPPLIERS.TYPE_1099%TYPE,
WITHHOLDING_STATUS_LOOKUP_CODE AP_SUPPLIERS.WITHHOLDING_STATUS_LOOKUP_CODE%TYPE,
WITHHOLDING_START_DATE AP_SUPPLIERS.WITHHOLDING_START_DATE%TYPE,
ORGANIZATION_TYPE_LOOKUP_CODE AP_SUPPLIERS.ORGANIZATION_TYPE_LOOKUP_CODE%TYPE,
START_DATE_ACTIVE AP_SUPPLIERS.START_DATE_ACTIVE%TYPE,
END_DATE_ACTIVE AP_SUPPLIERS.END_DATE_ACTIVE%TYPE,
MINORITY_GROUP_LOOKUP_CODE AP_SUPPLIERS.MINORITY_GROUP_LOOKUP_CODE%TYPE,
WOMEN_OWNED_FLAG AP_SUPPLIERS.WOMEN_OWNED_FLAG%TYPE,
SMALL_BUSINESS_FLAG AP_SUPPLIERS.SMALL_BUSINESS_FLAG%TYPE,
HOLD_FLAG AP_SUPPLIERS.HOLD_FLAG%TYPE,
PURCHASING_HOLD_REASON AP_SUPPLIERS.PURCHASING_HOLD_REASON%TYPE,
HOLD_BY NUMBER,
HOLD_DATE AP_SUPPLIERS.HOLD_DATE%TYPE,
TERMS_DATE_BASIS AP_SUPPLIERS.TERMS_DATE_BASIS%TYPE,
INSPECTION_REQUIRED_FLAG AP_SUPPLIERS.INSPECTION_REQUIRED_FLAG%TYPE,
RECEIPT_REQUIRED_FLAG AP_SUPPLIERS.RECEIPT_REQUIRED_FLAG%TYPE,
QTY_RCV_TOLERANCE NUMBER,
QTY_RCV_EXCEPTION_CODE AP_SUPPLIERS.QTY_RCV_EXCEPTION_CODE%TYPE,
ENFORCE_SHIP_TO_LOCATION_CODE AP_SUPPLIERS.ENFORCE_SHIP_TO_LOCATION_CODE%TYPE,
DAYS_EARLY_RECEIPT_ALLOWED NUMBER,
DAYS_LATE_RECEIPT_ALLOWED NUMBER,
RECEIPT_DAYS_EXCEPTION_CODE AP_SUPPLIERS.RECEIPT_DAYS_EXCEPTION_CODE%TYPE,
RECEIVING_ROUTING_ID NUMBER,
ALLOW_SUBSTITUTE_RECEIPTS_FLAG AP_SUPPLIERS.ALLOW_SUBSTITUTE_RECEIPTS_FLAG%TYPE,
ALLOW_UNORDERED_RECEIPTS_FLAG AP_SUPPLIERS.ALLOW_UNORDERED_RECEIPTS_FLAG%TYPE,
HOLD_UNMATCHED_INVOICES_FLAG AP_SUPPLIERS.HOLD_UNMATCHED_INVOICES_FLAG%TYPE,
TAX_VERIFICATION_DATE AP_SUPPLIERS.TAX_VERIFICATION_DATE%TYPE,
NAME_CONTROL AP_SUPPLIERS.NAME_CONTROL%TYPE,
STATE_REPORTABLE_FLAG AP_SUPPLIERS.STATE_REPORTABLE_FLAG%TYPE,
FEDERAL_REPORTABLE_FLAG AP_SUPPLIERS.FEDERAL_REPORTABLE_FLAG%TYPE,
ATTRIBUTE_CATEGORY AP_SUPPLIERS.ATTRIBUTE_CATEGORY%TYPE,
ATTRIBUTE1 AP_SUPPLIERS.ATTRIBUTE1%TYPE,
ATTRIBUTE2 AP_SUPPLIERS.ATTRIBUTE2%TYPE,
ATTRIBUTE3 AP_SUPPLIERS.ATTRIBUTE3%TYPE,
ATTRIBUTE4 AP_SUPPLIERS.ATTRIBUTE4%TYPE,
ATTRIBUTE5 AP_SUPPLIERS.ATTRIBUTE5%TYPE,
ATTRIBUTE6 AP_SUPPLIERS.ATTRIBUTE6%TYPE,
ATTRIBUTE7 AP_SUPPLIERS.ATTRIBUTE7%TYPE,
ATTRIBUTE8 AP_SUPPLIERS.ATTRIBUTE8%TYPE,
ATTRIBUTE9 AP_SUPPLIERS.ATTRIBUTE9%TYPE,
ATTRIBUTE10 AP_SUPPLIERS.ATTRIBUTE10%TYPE,
ATTRIBUTE11 AP_SUPPLIERS.ATTRIBUTE11%TYPE,
ATTRIBUTE12 AP_SUPPLIERS.ATTRIBUTE12%TYPE,
ATTRIBUTE13 AP_SUPPLIERS.ATTRIBUTE13%TYPE,
ATTRIBUTE14 AP_SUPPLIERS.ATTRIBUTE14%TYPE,
ATTRIBUTE15 AP_SUPPLIERS.ATTRIBUTE15%TYPE,
AUTO_CALCULATE_INTEREST_FLAG AP_SUPPLIERS.AUTO_CALCULAT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RIBUTE13 AP_SUPPLIERS.GLOBAL_ATTRIBUTE13%TYPE,
GLOBAL_ATTRIBUTE14 AP_SUPPLIERS.GLOBAL_ATTRIBUTE14%TYPE,
GLOBAL_ATTRIBUTE15 AP_SUPPLIERS.GLOBAL_ATTRIBUTE15%TYPE,
GLOBAL_ATTRIBUTE16 AP_SUPPLIERS.GLOBAL_ATTRIBUTE16%TYPE,
GLOBAL_ATTRIBUTE17 AP_SUPPLIERS.GLOBAL_ATTRIBUTE17%TYPE,
GLOBAL_ATTRIBUTE18 AP_SUPPLIERS.GLOBAL_ATTRIBUTE18%TYPE,
GLOBAL_ATTRIBUTE19 AP_SUPPLIERS.GLOBAL_ATTRIBUTE19%TYPE,
GLOBAL_ATTRIBUTE20 AP_SUPPLIERS.GLOBAL_ATTRIBUTE20%TYPE,
GLOBAL_ATTRIBUTE_CATEGORY AP_SUPPLIERS.GLOBAL_ATTRIBUTE_CATEGORY%TYPE,
BANK_CHARGE_BEARER AP_SUPPLIERS.BANK_CHARGE_BEARER%TYPE,
MATCH_OPTION AP_SUPPLIERS.MATCH_OPTION%TYPE,
CREATE_DEBIT_MEMO_FLAG AP_SUPPLIERS.CREATE_DEBIT_MEMO_FLAG%TYPE,
PARTY_ID NUMBER,
PARENT_PARTY_ID NUMBER,
JGZZ_FISCAL_CODE VARCHAR2(20),
SIC_CODE VARCHAR2(30),
TAX_REFERENCE VARCHAR2(50),
INVENTORY_ORGANIZATION_ID NUMBER,
TERMS_NAME AP_TERMS_TL.NAME%TYPE,
DEFAULT_TERMS_ID NUMBER,
VENDOR_INTERFACE_ID NUMBER,
NI_NUMBER AP_SUPPLIERS.NI_NUMBER%TYPE,
EXT_PAYEE_REC IBY_DISBURSEMENT_SETUP_PUB.EXTERNAL_PAYEE_REC_TYPE,
-- Bug 7437549 Start
EDI_PAYMENT_FORMAT AP_SUPPLIERS_INT.EDI_PAYMENT_FORMAT%TYPE,
EDI_TRANSACTION_HANDLING AP_SUPPLIERS_INT.EDI_TRANSACTION_HANDLING%TYPE,
EDI_PAYMENT_METHOD AP_SUPPLIERS_INT.EDI_PAYMENT_METHOD%TYPE,
EDI_REMITTANCE_METHOD AP_SUPPLIERS_INT.EDI_REMITTANCE_METHOD%TYPE,
EDI_REMITTANCE_INSTRUCTION AP_SUPPLIERS_INT.EDI_REMITTANCE_INSTRUCTION%TYPE
-- Bug 7437549 End
,URL HZ_CONTACT_POINTS.URL%TYPE, -- B# 7831956
-- B# 7583123
SUPPLIER_NOTIF_METHOD AP_SUPPLIERS_INT.SUPPLIER_NOTIF_METHOD%TYPE,
REMITTANCE_EMAIL AP_SUPPLIERS_INT.REMITTANCE_EMAIL%TYPE
,CEO_NAME AP_SUPPLIERS_INT.CEO_NAME%TYPE -- B# 9081643
,CEO_TITLE AP_SUPPLIERS_INT.CEO_TITLE%TYPE -- B# 9081643
,VAT_CODE AP_SUPPLIERS.VAT_CODE%TYPE -- B#9202909
,AUTO_TAX_CALC_FLAG AP_SUPPLIERS.AUTO_TAX_CALC_FLAG%TYPE -- B#9202909
,OFFSET_TAX_FLAG AP_SUPPLIERS_INT.OFFSET_TAX_FLAG%TYPE -- B#9202909
,VAT_REGISTRATION_NUM AP_SUPPLIERS_INT.VAT_REGISTRATION_NUM%TYPE -- B#9202909
);
编辑:根据安东尼的建议,我尝试使用自己创作的记录:
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_Oracle 中记录时,我得到:
cx_Oracle.DatabaseError: ORA-04043: object XX_SUPPLIERS_PKG_REC_TEST does not exist
我从 Oracle SQL Developer 检查了 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 RECORD 类型。这会导致类似的错误:
cx_Oracle.DatabaseError: ORA-04043: object PL/SQL RECORD does not exist