DatabaseError:ORA-00933:SQL命令未正确结束cx_Oracle

时间:2012-08-15 03:56:03

标签: python oracle ora-00933

当我运行以下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()

0 个答案:

没有答案