数据库错误:ORA00933:SQL命令未以cx正确结束_

2024-10-01 17:29:51 发布

您现在位置:Python中文网/ 问答频道 /正文

当我运行下面的Python代码时,我一直收到错误“DatabaseError:ORA-00933:SQL命令未正确结束”。奇怪的是,当我在squirrell(一个数据库客户机)中运行调试期间复制的sql时,它工作得很好。我用的是甲骨文。有人知道可能出了什么问题吗?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()

Tags: andaspriceportalwhencasetheninstr

热门问题