错误ORA-00933:SQL命令未正确结束

时间:2012-10-09 09:20:18

标签: oracle plsql

PROCEDURE PR_TRIAL_BAL_BULKWITHOUTCUR IS


VAR_OF_TYP_TBL TYP_TBL;

BEGIN
SELECT * BULK COLLECT INTO VAR_OF_TYP_TBL 
  FROM (SELECT NAME, SUM(CREDIT) AS CREDIT, SUM(DEBIT) AS DEBIT
          FROM (SELECT (SELECT GL_NAME
                          FROM QM_GL
                         WHERE QM_GL.GL_ID = QT_ACCOUNTING.GL_ID) AS NAME,
                       DECODE(QT_ACCOUNTING.TRANS_TYPE,
                              'CR',
                              (QT_ACCOUNTING.TRANS_AMOUNT),
                              0.00) AS CREDIT,
                       DECODE(QT_ACCOUNTING.TRANS_TYPE,
                              'DR',
                              (QT_ACCOUNTING.TRANS_AMOUNT),
                              0.00) AS DEBIT

                  FROM QT_ACCOUNTING, QM_ACCOUNTING_PERIOD

                 WHERE QT_ACCOUNTING.VALUE_DATE BETWEEN
                       QM_ACCOUNTING_PERIOD.PERIODFROM AND
                       QM_ACCOUNTING_PERIOD.PERIODTO
                   AND QM_ACCOUNTING_PERIOD.STATUS = 'O')
         GROUP BY NAME)
         );

FOR I IN 1 .. VAR_OF_TYP_TBL.COUNT LOOP

  IF (VAR_OF_TYP_TBL(I).CREDIT - VAR_OF_TYP_TBL(I).DEBIT) > 0 THEN
    INSERT INTO TBL_TRIAL_BALANCE_REPORT
    VALUES
      (VAR_OF_TYP_TBL(I).NAME,
       (VAR_OF_TYP_TBL(I).CREDIT - VAR_OF_TYP_TBL(I).DEBIT),
       0);
  END IF;
  IF (VAR_OF_TYP_TBL(I).DEBIT - VAR_OF_TYP_TBL(I).CREDIT) > 0 THEN
    INSERT INTO TBL_TRIAL_BALANCE_REPORT
    VALUES
      (VAR_OF_TYP_TBL(I).NAME,
       0,
       (VAR_OF_TYP_TBL(I).DEBIT - VAR_OF_TYP_TBL(I).CREDIT));
  END IF;

END LOOP;
VAR_OF_TYP_TBL.DELETE;

EXCEPTION
  WHEN OTHERS THEN
  DBMS_OUTPUT.PUT_LINE(SQLERRM);
  BEGIN
    VAR_OF_TYP_TBL.DELETE;
  EXCEPTION
    WHEN OTHERS THEN
      NULL;
  END;
END;

任何人都可以帮助我,上面代码中的错误在哪里以及如何删除?

  • ORA-00933:SQL命令未正确结束
  • 错误:PL / SQL:忽略SQL语句

(错误仅在选择查询中)

1 个答案:

答案 0 :(得分:1)

    SELECT   *
      BULK   COLLECT
      INTO   VAR_OF_TYP_TBL
      FROM   (  SELECT   NAME, SUM (CREDIT) AS CREDIT, SUM (DEBIT) AS DEBIT
                  FROM   (SELECT   (SELECT   GL_NAME
                                      FROM   QM_GL
                                     WHERE   QM_GL.GL_ID = QT_ACCOUNTING.GL_ID)
                                      AS NAME,
                                   DECODE (QT_ACCOUNTING.TRANS_TYPE,
                                           'CR', (QT_ACCOUNTING.TRANS_AMOUNT),
                                           0.00)
                                      AS CREDIT,
                                   DECODE (QT_ACCOUNTING.TRANS_TYPE,
                                           'DR', (QT_ACCOUNTING.TRANS_AMOUNT),
                                           0.00)
                                      AS DEBIT
                            FROM   QT_ACCOUNTING, QM_ACCOUNTING_PERIOD
                           WHERE   QT_ACCOUNTING.VALUE_DATE BETWEEN QM_ACCOUNTING_PERIOD.PERIODFROM
                                                                AND  QM_ACCOUNTING_PERIOD.PERIODTO
                                   AND QM_ACCOUNTING_PERIOD.STATUS = 'O')
              GROUP BY   NAME);
          -- );       remove this from your code