python - cx_Oracle - 未实现 Oracle 类型 2010 和 native 类型 3000 之间的转换

标签 python oracle cx-oracle user-defined-types

我正在尝试使用 cx_Oracle 从用户定义类型 (UDT) 中提取数据。我可以毫无问题地提取某些 UDT 的数据,但对于一个特定的 UDT,我无法提取数据。 Oracle中类型的结构:

CREATE OR REPLACE TYPE graphic_component AS OBJECT (
   type             NUMBER(6),
   source_type      NUMBER(4),
   meta_type_id     VARCHAR2(50 CHAR),
   name             VARCHAR2(100 CHAR),
   extension_info   VARCHAR2(500 CHAR),
   symbology_tokens VARCHAR2(2000 CHAR)
);

CREATE OR REPLACE TYPE graphic_component_array AS
      VARRAY (10000) OF graphic_component;

在 Python 中,使用此代码提取 UDT ( code from here ):

def ObjectRepr(obj):
    if obj.type.iscollection:
        returnValue = []
        for value in obj.aslist():
            if isinstance(value, cx_Oracle.Object):
                value = ObjectRepr(value)
            returnValue.append(value)
    else:
        returnValue = {}
        for attr in obj.type.attributes:
            value = getattr(obj, attr.name)
            if value is None:
                continue
            elif isinstance(value, cx_Oracle.Object):
                value = ObjectRepr(value)
            returnValue[attr.name] = value
    return returnValue

然后,如果我尝试从 UDT 中提取数据,则会收到此错误:

<cx_Oracle.Object GRAPHIC_COMPONENT_ARRAY at 0x26c9f10>
Traceback (most recent call last):
  File "C:/Users/petr.silhak/PycharmProjects/migration-to-postgresql/test_parsing.py", line 34, in <module>
    print(ObjectRepr(complex[0][0]))
  File "C:/Users/petr.silhak/PycharmProjects/migration-to-postgresql/test_parsing.py", line 9, in ObjectRepr
    value = ObjectRepr(value)
  File "C:/Users/petr.silhak/PycharmProjects/migration-to-postgresql/test_parsing.py", line 14, in ObjectRepr
    value = getattr(obj, attr.name)
cx_Oracle.DatabaseError: DPI-1014: conversion between Oracle type 2010 and native type 3000 is not implemented

看起来像 Oracle odpi 有问题数据类型的转换。在这个特定的示例中,数据看起来像这样(来自 SQL 开发人员):

GRAPHIC_COMPONENT(1007,17,'gtda_5012101_1',NULL,NULL,NULL,NULL)

最佳答案

检查您的 cx_Oracle 版本。
It looks like 2017 年 9 月添加了从 DPI_ORACLE_TYPE_NUMBER(2010)DPI_NATIVE_TYPE_INT64(3000) 转换的支持。

关于python - cx_Oracle - 未实现 Oracle 类型 2010 和 native 类型 3000 之间的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49109582/

相关文章:

python - 如何将 Pandas 时区感知时间戳转换为 UNIX 纪元?

sql - 总结Oracle中的空行

python - 编程错误 : LOB variable no longer valid after subsequent fetch

python - 写入 Oracle : TypeError: expecting string or bytes object

python - 从 cx_oracle 执行一个 sql 脚本文件?

Python 转换矩阵

python - 如何在处理完 30 个元素后以间隔(5 分钟)处理一个大列表?

python - 如何在 TensorFlow 中沿某个维度选择张量的元素(不是切片)

sql - 如何在 Oracle SQL Developer 中转义下划线?

oracle - 有没有办法列出 ORACLE 查询中使用的表和列?