Je mag collections.namedtuple
niet rechtstreeks gebruiken als Oracle-objecttype.
Ik heb het onderstaande geprobeerd op Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 met Cx-Oracle-7.0.0
en Python 3.6.4 en het werkt voor mij.
TYPE maken
CREATE OR REPLACE TYPE object_tag_rec AS OBJECT (
tag_type VARCHAR2(1),
tag_category VARCHAR2(100),
tag_key VARCHAR2(250),
tag_value VARCHAR2(250),
created_by VARCHAR2(50)
);
/
Collectie maken
CREATE OR REPLACE TYPE object_tag_tbl is TABLE OF object_tag_rec;
/
Procedure maken
CREATE OR REPLACE procedure sp_add_object_tags(
pi_account_id IN INT,
pi_object_id IN INT,
pi_all_tags_identified IN VARCHAR2,
pi_object_tag_tbl IN object_tag_tbl,
po_error_code OUT NUMBER,
po_error_message OUT VARCHAR2 )
AS
BEGIN
po_error_code := 0;
po_error_message := 'NO ERRORS';
END;
/
code
import cx_Oracle
conn = cx_Oracle.connect('user/[email protected]//localhost:1521/dbname')
cur = conn.cursor()
recordTypeObj = conn.gettype("HR.OBJECT_TAG_REC") #mind the cases
tableTypeObj = conn.gettype("HR.OBJECT_TAG_TBL")
params = tableTypeObj.newobject()
rec = recordTypeObj.newobject()
(rec.TAG_TYPE,rec.TAG_CATEGORY,rec.TAG_KEY,rec.TAG_VALUE,rec.CREATED_BY) = ("S","person","person","1","abc")
#mind the cases for attributes.
po_error_code = cur.var(cx_Oracle.NUMBER)
po_error_message = cur.var(cx_Oracle.STRING)
params.append(rec)
cur.callproc('dbms_output.enable')
cur.callproc('hr.sp_add_object_tags', [1234, 5678, 'N', params, po_error_code, po_error_message])
print (po_error_code.getvalue(),po_error_message.getvalue())
Uitvoering
$python pass_obj.py
0.0 NO ERRORS