2016-08-04 120 views
2

我正在使用python從Oracle DB中獲取數據。所有的行都有一個包含XML數據的列。當我使用python打印從Oracle DB中獲取的數據時,包含XML數據的列被打印爲0x7fffe373b960處的 - cx_Oracle.OBJECT對象等。我甚至將數據轉換爲pandas數據框,並且仍然將此列的數據打印爲cx_Oracle。 OBJECT對象在0x7fffe373b960。我想訪問存儲在此列中的鍵值數據(XML文件)。Python,Oracle數據庫,列中的XML數據,提取cx_Oracle.Object

回答

2

請閱讀內置評論。

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