UNION / ORA-00933:SQL命令未正确结束

时间:2014-09-12 13:43:39

标签: sql oracle11g

我得到了一个" ORA-00933: SQL command not properly ended"运行此代码时出现错误消息。我检查过逗号,括号等,但找不到这个问题。有什么建议?这是我第一次在代码中使用UNION ALL。工会的第一部分完全符合我的要求。我已经添加了工会的第二部分,因为我只想要2014财年和会计期间11的那些字段。即使我在第一部分中想要它,我也不希望这部分的会计期间10的信息。谢谢你的帮助

Select
    Bus_UNIT, 
    DESCRIPT,
    DEPTID,
    ASSET_NO,
    ACCT_AD,
    BOOK,
    CURRENT_AMT,
    PRIOR_AMT,
    ACCT_DE,
    JRNL_ID,
    JRNL_DT    
From ( SELECT 
    pa.BUSINESS_UNIT as BUS_UNIT, 
    pa.DESCR AS DESCRIPT,
    pdr.DEPTID AS DEPTID, 
    pdr.ASSET_ID AS ASSET_NO, 
    pdr.ACCOUNT_AD AS ACCT_AD, 
    pdr.BOOK AS BOOK,

    MAX(CASE WHEN (pdr.FISCAL_YEAR =2014 AND pdr.ACCOUNTING_PERIOD =11) THEN  pdr.DEPR END) as CURRENT_AMT,
    MAX(CASE WHEN (pdr.FISCAL_YEAR =2104 AND pdr.ACCOUNTING_PERIOD =10) THEN pdr.DEPR  END) as PRIOR_AMT,

    '' AS ACCT_DE,
    '' AS JRNL_ID,
    '' AS JRNL_DT

    FROM PS_ASSET pa

    INNER JOIN PS_DEPR_RPT pdr 
    ON pa.ASSET_ID = pdr.ASSET_ID
    AND pa.BUSINESS_UNIT = pdr.BUSINESS_UNIT

    WHERE 
    pa.BUSINESS_UNIT='A0465'
    AND pdr.BOOK='PERFORM'
    AND ((pdr.FISCAL_YEAR=2014 AND pdr.ACCOUNTING_PERIOD=11) 
    OR (pdr.FISCAL_YEAR=2014 AND pdr.ACCOUNTING_PERIOD=10))

    group by
    pa.business_unit,
    pa.descr,
    pdr.deptid,
    pdr.asset_id,
    pdr.account_ad,
    pdr.book

UNION ALL

    select
    '' as BUS_UNT,
    '' AS DESCRIPT,
    '' AS DEPTID, 
    '' AS ACCT_AD, 
    '' AS BOOK,
    '' AS CURRENT_AMT,
    '' AS PRIOR_AMT,
    pdl.asset_id AS ASSET_NO,
    pdl.account AS ACCT_DE,
    pdl.journal_id AS JRNL_ID,
    pdl.journal_date AS JRNL_DT

    from ps_dist_ln pdl

    where
    book = 'PERFORM'
    and business_unit = 'A0465'
    and fiscal_year = 2014
    and accounting_period = 11
    and distribution_type = 'DE'
) as TEST    
group BY ASSET_NO;

1 个答案:

答案 0 :(得分:0)

Oracle不允许as表别名。只需删除as

即可

as对于列别名是可选的,但强烈建议。