【问题标题】:Python, Oracle DB, XML data in a column, fetching cx_Oracle.ObjectPython,Oracle DB,列中的 XML 数据,获取 cx_Oracle.Object
【发布时间】:2017-03-03 22:49:06
【问题描述】:

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

【问题讨论】:

    标签: python xml oracle pandas clob


    【解决方案1】:

    请阅读内联 cmets。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-21
      • 1970-01-01
      • 1970-01-01
      • 2018-11-04
      • 2021-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多