Extract Data From User Defined Type Via Cx_oracle
I am trying to extract data from User defined type (UDT) via cx_Oracle. Here is the UDT structure: CREATE OR REPLACE TYPE graphic_component AS OBJECT ( type NUMBER(6
Solution 1:
Here is the piece of code that handles complex types in cx_Oracle. Excerpt:
defObjectRepr(obj):
if obj.type.iscollection:
returnValue = []
for value in obj.aslist():
ifisinstance(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 isNone:
continueelifisinstance(value, cx_Oracle.Object):
value = ObjectRepr(value)
returnValue[attr.name] = value
return returnValue
You use it like ObjectRepr(complex[0][0])
, if len(complex)>0
, of course
Post a Comment for "Extract Data From User Defined Type Via Cx_oracle"