代码抛出错误ORA-00907:缺少右括号

时间:2018-03-29 03:53:07

标签: database oracle plsql integration plsqldeveloper

有人可以向我解释为什么会出现这个错误吗?

SELECT CONTRACT_ID, DATEKEY, 'Projection', '1', OPEN_BALANCE,
  PRINC_REPAYMENT, INTEREST, PAR_PREPAYMENT, FULL_REDEMPTION, REDRAW_AMOUNT, PRIN_DEFAULTS,
  PRIN_RECOVERY, PRIN_DEL, INTE_DEL, DEL_PRIN_COLL, DEL_INT_COLL, CLOSE_PRIN_BAL, EXT_ID,
  LAS_ACTIVE_FLG, PROD_ID, ASSET_TYP_ID, CPT_ID, ACCRETION, CASHFLOW_DT 
FROM FACT_PWOR_CASHFLOW
WHERE ACTUAL_FLG = 'Y' AND LATEST_PROJ_IND = '0' AND LAS_ACTIVE_FLG = 'Y'
UNION
(SELECT CONTRACT_ID, DATEKEY_COLL, 'Actual', '1', SUM(OPENING_BALANCE) SUM_OPEN_BAL,
    SUM(MI_PRINCIPLE) SUM_MI_PRIN, SUM(MI_INTEREST) SUM_MI_INTER, SUM(PARTIAL_PREPAYMENT) SUM_PAR_PREPAY,
    SUM(FULL_REDEMPTION) SUM_FULL_REDEM, SUM(TTL_AMT_REDRAW) SUM_TTL_AMT,
    '0', '0', '0', '0', '0', '0', SUM(CLOSING_BALANCE) SUM_CLOS_BAL, '0', 'Y',
    PROD_ID, ASSET_TYPE_ID, CPT_ID, '0', COLLECTION_START_DT
FROM FACT_PWOR_COLLECTION
WHERE LAS_ACTIVE_FLG = 'Y'
GROUP BY CONTRACT_ID, DATEKEY_COLL, PROD_ID, ASSET_TYPE_ID, CPT_ID, COLLECTION_START_DT
ORDER BY CONTRACT_ID, DATEKEY_COLL);

1 个答案:

答案 0 :(得分:1)

此错误非常常见,因为您的嵌套查询中有ORDER BY(请参阅第二个SELECT中使用括号的位置)。 Oracle不支持它,因此它会给你这个错误。您可以在没有嵌套查询的情况下重写它,或者删除顺序,它应该可以工作