查询在SQL Developer中有效但在Putty中不起作用(ORA-00907,缺少括号)

时间:2016-10-20 04:43:08

标签: sql oracle parentheses

你能看到这个代码丢失的迹象吗?如果这太久了,我很抱歉。这是两个段(MTD和YTD)的完全外连接。结果预计以逗号分隔。这在SQL Developer中完美运行,但在Unix(Putty)中却不行。

select mtd.portfolio||','||
        mtd.descr||','||
        mtd.ccy||','||
        CASE WHEN ytd.ytd_amnt IS NOT NULL THEN
          CASE WHEN substr(mtd.acnt,1,1) in ('2','5','0') --base currency month to date
          THEN (sum(ytd.ytd_amnt_bc) - sum(mtd.mtd_amnt_bc))*-1
            ELSE (sum(ytd.ytd_amnt_bc) - sum(mtd.mtd_amnt_bc)) 
          END
        ELSE
          0
        END
        ||','||   
        CASE WHEN mtd.ccy in ('USD') THEN
          CASE WHEN substr(mtd.acnt,1,1) in ('2','5','0') THEN  --base currency year to date
                 sum(mtd.mtd_amnt)*-1        
          ELSE
                 sum(mtd.mtd_amnt)        
           END
         ELSE
           CASE WHEN substr(mtd.acnt,1,1)in ('2','5','0') THEN   
                 sum(mtd.mtd_amnt_bc)*-1
          ELSE
                 sum(mtd.mtd_amnt_bc)
           END
         END
        ||','||
      CASE WHEN ytd.ytd_amnt IS NOT NULL THEN
          CASE WHEN substr(mtd.acnt,1,1)in ('2','5','0') THEN    --native currency month to date
           (sum(ytd.ytd_amnt) - sum(mtd.mtd_amnt)) *-1
            ELSE 
           sum(ytd.ytd_amnt) - sum(mtd.mtd_amnt) 
          END
      ELSE
          0
        END||','||
        CASE WHEN mtd.ccy in ('PHP') THEN --native currency year to date 
          CASE WHEN substr(mtd.acnt,1,1)in ('2','5','0') THEN   
                 mtd.mtd_amnt*-1
          ELSE
                 mtd.mtd_amnt
          END
         ELSE
           CASE WHEN substr(mtd.acnt,1,1)in ('2','5','0') THEN   
                   sum(mtd.mtd_amnt_bc)*-1
            ELSE
                   sum(mtd.mtd_amnt_bc)
           END
         END||','||  
        CASE WHEN substr(mtd.acnt,1,1)='0' 
        THEN '5' 
        ELSE substr(mtd.acnt,1,1) 
        END      
    from 
    (select (accl.acnt) acnt, (kp.account) portfolio, (accc.descr)descr, (accl.curr) ccy, sum(accl.amnt_bc) mtd_amnt_bc, sum(accl.amnt) mtd_amnt
    from acc$ledger accl
      LEFT JOIN k$portfolio kp ON kp.id = accl.portfolio
      LEFT JOIN acc$chart accc ON accc.acnt = accl.acnt
    where accl.company = accc.company
    and accl.company <> 1
    and substr(accl.acnt,1,1) in ('0','1','2','5')
  and accc.fisc_yr in (select to_char(current_business_date,'YYYY') from k$company where id=1)
    and accl.account_dte <> to_date('0001-01-01','YYYY-MM-DD')  
  and accl.dt <= (select last_day(add_months(current_business_date,-1)) from k$company where id=1)
    group by  accc.descr, kp.account, accl.acnt, accl.curr
    order by kp.account, accl.acnt
    )
  mtd full outer join

    (select (accl.acnt) acnt, (kp.account) portfolio, (accc.descr)descr, sum(accl.amnt_bc) ytd_amnt_bc, sum(accl.amnt) ytd_amnt
    from acc$ledger accl
      LEFT JOIN k$portfolio kp ON kp.id = accl.portfolio
      LEFT JOIN acc$chart accc ON accc.acnt = accl.acnt
    where accl.company = accc.company   
    and accl.company <> 1
    and substr(accl.acnt,1,1) in ('0','1','2','5') 
    and accc.fisc_yr in (select to_char(current_business_date,'YYYY') from k$company where id=1)
    and accl.account_dte <> to_date('0001-01-01','YYYY-MM-DD') 
  and accl.dt <= (select last_day(add_months(current_business_date,-2)) from k$company where id=1)
    group by  accc.descr, kp.account, accl.acnt
    order by kp.account, accl.acnt)
    ytd
    on mtd.portfolio=ytd.portfolio
    and mtd.descr=ytd.descr
    and mtd.acnt= ytd.acnt
    group by mtd.acnt, mtd.portfolio, mtd.descr, mtd.ccy, mtd.mtd_amnt, ytd.ytd_amnt 
    order by mtd.portfolio, mtd.acnt, mtd.descr;

1 个答案:

答案 0 :(得分:1)

删除空换行符。默认情况下,SQL * Plus使用空换行来终止SQL语句。 SQL Developer的工作方式不同,具体取决于您运行查询的方式。