gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 03:08:39 25 4
gpt4 key购买 nike

我正在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com