2

次の Python コードを実行すると、「DatabaseError: ORA-00933: SQL コマンドが正しく終了していません」というエラーが表示され続けます。奇妙なことに、デバッグ中にコピーした sql をデータベース クライアントである SQuirrel で実行すると、問題なく動作します。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()
4

0 に答える 0