pyodbc:包含PIVOT的查询

时间:2018-07-19 08:40:41

标签: python oracle pivot pyodbc

我在包含PIVOT(Oracle)语句的oracle查询中遇到问题!

我从表中获取数据没有问题,但是如果查询包含数据透视语句,则会出现错误:

File "C:\ProgramData\Anaconda2\lib\site-packages\pandas\io\sql.py", line 1440, in read_query
    columns = [col_desc[0] for col_desc in cursor.description]

TypeError: 'NoneType' object is not iterable

有关如何解决此问题的任何想法? 提前感谢:)

我的代码:

import pyodbc
from pandas import read_sql_query

dbInst = XXX
schema = YYY
passwd = ZZZ

connString = "Driver={Microsoft ODBC for Oracle};Server=" +  dbInst + ';Uid=' + schema + ';Pwd=' + passwd + ";"

sqlWorks = """
select 'A' as  state, 1 as value from dual
"""

sqlDoesNotWork = """
With T As 
(
  select 'A' as  state, 1 as value from dual
)
Select *
From T
Pivot
(
  Sum(Value)
  For State In ('A' As States)
)
"""

conn = pyodbc.connect(connString)
data = read_sql_query(sqlWorks, conn)
print data

data2 = read_sql_query(sqlDoesNotWork, conn)
print data2

0 个答案:

没有答案