我的工作的Python记录模块的一个处理程序。基本上登录到Oracle数据库。

我使用cx_oracle,和一些我不知道如何得到的是列值时,表是空的。

cursor.execute('select * from FOO')
for row in cursor:
    # this is never executed because cursor has no rows
    print '%s\n' % row.description

# This prints none
row = cursor.fetchone()
print str(row)

row = cursor.fetchvars
# prints useful info
for each in row:
    print each

的输出是:

None
<cx_Oracle.DATETIME with value [None, None, None, None, None, None, None, None, None, None, None, None, None, None, None
, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None
, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None]>
<cx_Oracle.STRING with value [None, None, None, None, None, None, None, None, None, None, None, None, None, None, None,
None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None,
None, None, None, None, None, None, None, None, None, None, None, None, None, None, None]>

现在看VAR数据,我可以看到的数据类型,以及它们的大小(计数诺内斯?),但多数民众赞成缺少列名。

我怎么能去呢?

有帮助吗?

解决方案

我认为 description 属性可以是你所寻找的。这将返回描述返回的数据列的元组的列表。它的工作原理很愉快,如果没有返回的行,例如:

>>> import cx_Oracle
>>> c = cx_Oracle.connect("username", "password")
>>> cr = c.cursor()
>>> cr.execute("select * from dual where 1=0")
<__builtin__.OracleCursor on <cx_Oracle.Connection to user username@local>>
>>> cr.description
[('DUMMY', <type 'cx_Oracle.STRING'>, 1, 1, 0, 0, 1)]
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top