我正在尝试从此PL / SQL代码中获取python结果:
DECLARE
TYPE MyRecord IS RECORD (
state NUMBER,
text VARCHAR2(32),
dt DATE
);
TYPE MyRecordTable IS TABLE OF MyRecord;
recordTable MyRecordTable;
result MyRecordTable;
FUNCTION peek RETURN MyRecordTable
IS
recordTable MyRecordTable;
BEGIN
recordTable := MyRecordTable();
recordTable.extend;
recordTable(recordTable.last).state := 4711;
recordTable(recordTable.last).text := 'Test';
RETURN recordTable;
END;
BEGIN
:result := peek;
END;
我不能使用行类型游标,因为在我的实际PL / SQL代码中,有函数调用,我希望将结果放入这样的用户记录表中。那可能吗? 我的Python代码如下所示:
dsn = cx_Oracle.makedsn(server, port, sid)
conn = cx_Oracle.connect(user, pw, dsn)
# Maybe there's a way using an output type handler?
conn.outputtypehandler = output_type_handler
cursor = conn.cursor()
result = cursor.var(cx_Oracle.OBJECT)
cursor.execute(PLSQL, result = result)
# This would be nice, if it worked:
#result = cursor.fetchall()
cursor.close()
conn.close()