Python DB找到的行作为对象打印,而不是"d"

2024-04-26 22:04:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我从Python开始,目前正在尝试以下基础知识:

import cx_Oracle
con = cx_Oracle.connect('user/pass@hostname/DBName')
cursor = con.cursor()

cursor.execute("""
        select * from
        (select definition_code, content_data, creation_date
        from acms_content
        order by creation_date desc)
        where rownum <= 4
        """)
for column_1, column_2, column_3 in cursor:
    print ("Values:", column_1, column_2, column_3)


print (con.version)
con.close()

现在我通过python3.5运行它连接.py,我得到:

Values: Something1 <cx_Oracle.OBJECT object at 0x2aacb49c7a08> 2016-06-02 16:48:50    
Values: Something2 <cx_Oracle.OBJECT object at 0x2aacb49c78f0> 2016-06-02 16:09:01    
Values: Something3 <cx_Oracle.OBJECT object at 0x2aacb49c7a08> 2016-06-02 15:50:29    
Values: Something4 <cx_Oracle.OBJECT object at 0x2aacb49c78f0> 2016-06-02 13:07:48    
Values: Something5 <cx_Oracle.OBJECT object at 0x2aacb49c7998> 2016-06-02 09:39:46

为什么会这样?如何打印该对象的值? 我应该提到content_data列是XMLTYPE——基本上在oraclesqldeveloper中,双击单元格,就会显示其中的XML文本。如何使用Python实现这一点?你知道吗

另外,这只是我需要做的一些迁移脚本(文件、XMLs、DB条目)的前奏——因此,如果您能推荐一些好的快速阅读方法来正确、高效地编写Python代码并进行调试,请发布——我很乐意阅读。你知道吗


Tags: fromdatadateobjectcolumncontentconselect