当我运行以下 Python 代码时,我不断收到错误“DatabaseError:ORA-00933:SQL 命令未正确结束”。奇怪的是,当我在数据库客户端 SQuirrel 中运行我在调试期间复制的 sql 时,它工作得很好。我正在使用 cx_Oracle。有谁知道可能出了什么问题?names
是一个字典,在其值字段中包含客户名称。谢谢!
def getData(accts):
names = getNames(list(accts))
sql = """select
CustomerAcronym,
Portal,
CcyPair,
BuyCCY,
SellCCY,
count(PortalID) as TradeCount,
sum(BuyCCYAmt) as TtlBuyCcyAmt,
sum(SellCCYAmt) as TtlSellCcyAmt,
sum(USDEquiv) as USDEquivalent
from (
select
CustomerAcronym,
Portal,
CcyPair,
case
when DealtDirection = 'BUY' then DealtCcy
when DealtCcy = CCY1 then CCY2
else CCY1
end as BuyCCY,
case
when DealtDirection = 'SELL' then DealtCcy
when DealtCcy = CCY1 then CCY2
else CCY1
end as SellCCY,
case
when DealtDirection = 'BUY' then DealtAmount
when DealtCcy = substr(Price, 1,3) and instr(Price,'/') = 0 then DealtAmount*substr(Price, instr(Price,' ')+1)
when DealtCcy = substr(Price, 1,3) then DealtAmount*substr(Price, instr(Price,' ')+1, instr(Price,'/')-instr(Price,' ')-1)
when DealtCcy = substr(Price, 4,3) and instr(Price,'/') = 0 then DealtAmount/substr(Price, instr(Price,' ')+1)
when DealtCcy = substr(Price, 4,3) then DealtAmount/substr(Price, instr(Price,' ')+1, instr(Price,'/')-instr(Price,' ')-1)
end as BuyCCYAmt,
case
when DealtDirection = 'SELL' then DealtAmount
when DealtCcy = substr(Price, 1,3) and instr(Price,'/') = 0 then DealtAmount*substr(Price, instr(Price,' ')+1)
when DealtCcy = substr(Price, 1,3) then DealtAmount*substr(Price, instr(Price,' ')+1, instr(Price,'/')-instr(Price,' ')-1)
when DealtCcy = substr(Price, 4,3) and instr(Price,'/') = 0 then DealtAmount/substr(Price, instr(Price,' ')+1)
when DealtCcy = substr(Price, 4,3) then DealtAmount/substr(Price, instr(Price,' ')+1, instr(Price,'/')-instr(Price,' ')-1)
end as SellCCYAmt,
PortalID,
USDEquiv
from SALES_DATA
where
CustomerAcronym = 'ABCCORP' and
DealtFlag = 'DEALT' and
TDate > '2012-08-01'
) as temptbl
group by CustomerAcronym, Portal, CcyPair, BuyCCY, SellCCY
order by Portal, CcyPair"""
con = getConn()
try:
cursor = con.cursor()
cursor.execute(sql)
return cursor.fetchall()
finally:
con.close()