Python,Oracle DB,一列中的XML数据,获取cx_Oracle.Object

标签 python xml oracle pandas clob

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

最佳答案

请阅读内联评论。

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,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38755672/

相关文章:

Python API - 创建可选括号的模式?

python - sqlalchemy 中的 scoped_session 问题 - 它是如何工作的?

python - 如何使用用于 python-tornado 的 Facebook graph api 读取 facebook 用户的电子邮件?

python - 使用 python 更改 xml

oracle - 使用 Types.TIME 将 java.time.LocalTime 保留到 oracle 中会丢失小数秒精度

java - 无法从java向数据库添加新用户

python - SciPy:为什么二维插值的输入在内部排序?

java - java中的XML解析: how to get info out of a tag adjacent to a tag with a certain value?

sql-server - 为什么要使用交叉Apply来获取XML中的值?

sql - ORA-00905: 缺少关键字