本文介绍了列中的Python,Oracle DB,XML数据,获取cx_Oracle.Object的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python从Oracle DB中获取数据.所有行都有一个包含XML数据的列.当我打印使用python从Oracle DB获取的数据时,带有XML数据的列被打印为-cx_Oracle.OBJECT对象,位于0x7fffe373b960等.我什至将数据转换为pandas数据框,但该列的数据仍打印为cx_Oracle. OBJECT对象位于0x7fffe373b960.我想访问存储在此列中的键值数据(XML文件).

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).

推荐答案

请阅读内联注释.

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()

这篇关于列中的Python,Oracle DB,XML数据,获取cx_Oracle.Object的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 15:00