문제

파이썬 로깅 모듈의 핸들러를 작업 중입니다. 본질적으로 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 데이터를 살펴보면 데이터 유형과 크기 (Count Nones?)를 볼 수 있지만 열 이름이 누락되었습니다.

이것에 대해 어떻게 갈 수 있습니까?

도움이 되었습니까?

해결책

제 생각에는 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