Python, Oracle DB, XML data in a column, fetching cx_Oracle.Object

时光毁灭记忆、已成空白 提交于 2019-12-10 11:18:15

问题


I am using python to fetch data from Oracle DB. All the rows have a column which has XML data. When I print the data fetched from Oracle DB using python, the column with XML data is printed as - cx_Oracle.OBJECT object at 0x7fffe373b960 etc. I even converted the data to pandas data frame and still the data for this columns is printed as cx_Oracle.OBJECT object at 0x7fffe373b960. I want to access the key value data stored in this column(XML files).


回答1:


Please read inline comments.

cursor = connection.cursor() # you know what it is for

# here getClobVal() returns whole xml. It won't work without alias I don't know why.
query = """select a.columnName.getClobVal() from tablename a""" 

cursor.execute(query) #you know what it is for

result = cursor.fetchone()[0].read() # for single record

result = cursor.fetchall() # for all records
for res in result:  
    print res[0].read()


来源:https://stackoverflow.com/questions/38755672/python-oracle-db-xml-data-in-a-column-fetching-cx-oracle-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!