2016-11-03 61 views
-1

我在努力弄清楚爲什麼不編譯此代碼。確切的錯誤即時得到的是:PLS-00103:在期待以下某項時遇到符號「文件結束」:

ERROR at line 82: 
ORA-06550: line 82, column 4: 
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the 
following: 
(begin case declare end exit for goto if loop mod null 
pragma raise return select update while with <an identifier> 
<a double-quoted delimited-identifier> <a bind variable> << 
continue close current delete fetch lock insert open rollback 
savepoint set sql execute commit forall merge pipe purge 

我試圖做一堆的交易是取自一個臨時表「new_Transactions」,並把它們添加到另一個的情侶對錶,「帳戶」,「Transaction_History 「和」Transaction_Detail「。 new_transaction表可以爲每個事務處理多個借記和貸記,所以嵌套應該將所有事務讀入文件。

我一直在努力弄清楚錯誤發生在哪裏一段時間,我承認SQL不是我的強項,所以如果有非常可怕的錯誤,請讓我知道。

DECLARE 
r_transaction NEW_TRANSACTIONS%ROWTYPE; 
CURSOR c_trans_no IS 
SELECT * 
INTO r_transaction 
FROM new_transactions 
ORDER BY transaction_no; 

v_credit_check NEW_TRANSACTIONS.TRANSACTION_AMOUNT%TYPE; 
v_debit_check NEW_TRANSACTIONS.TRANSACTION_AMOUNT%TYPE; 


BEGIN 

FOR r_transaction IN C_trans_no LOOP 
    v_debit_check:=0; 
    v_credit_check:=0; 
      DECLARE 
       r_test NEW_TRANSACTIONS%ROWTYPE; 
       CURSOR c_new_trans IS 
       SELECT * 
       INTO r_test 
       FROM new_transactions 
       WHERE transaction_no = r_transaction.transaction_no; 

        BEGIN 
         FOR r_test IN c_new_trans LOOP 
         DECLARE 
         v_number NUMBER(8,2); 
         rec_account ACCOUNT%ROWTYPE; 
         BEGIN 
         SELECT * 
         INTO rec_account 
         FROM ACCOUNT 
         WHERE account_no = r_test.account_no; 

         INSERT INTO TRANSACTION_HISTORY(transaction_no, transaction_date, description) 
         VALUES (r_test.transaction_no, r_test.transaction_date, r_test.description); 
         INSERT INTO TRANSACTION_DETAIL(account_no, transaction_no, transaction_type, transaction_amount) 
         VALUES (r_test.account_no, r_test.transaction_no, r_test.transaction_type, r_test.transaction_amount); 

         IF(r_test.transaction_type = 'D') THEN 
          v_debit_check := v_debit_check + r_test.transaction_amount; 
          CASE rec_account.account_type_code 
           WHEN 'A' THEN v_number := r_test.transaction_amount; 
           WHEN 'L' THEN v_number := -r_test.transaction_amount; 
           WHEN 'EX' THEN v_number := r_test.transaction_amount; 
           WHEN 'RE' THEN v_number := -r_test.transaction_amount; 
           WHEN 'OE' THEN v_number := -r_test.transaction_amount; 
          END CASE; 
          UPDATE ACCOUNT 
          SET account_balance = account_balance + v_number 
          WHERE r_test.account_no = rec_account.account_no; 
         ELSIF(r_test.transaction_type = 'C') THEN 
          v_credit_check := v_credit_check + r_test.transaction_amount; 
          CASE rec_account.account_type_code 
           WHEN 'A' THEN v_number := -r_test.transaction_amount; 
           WHEN 'L' THEN v_number := r_test.transaction_amount; 
           WHEN 'EX' THEN v_number := -r_test.transaction_amount; 
           WHEN 'RE' THEN v_number := r_test.transaction_amount; 
           WHEN 'OE' THEN v_number := r_test.transaction_amount; 
          END CASE; 
          UPDATE ACCOUNT 
          SET account_balance = account_balance + v_number 
          WHERE r_test.account_no = rec_account.account_no; 
         --ELSE 
          --ROLLBACK; 
          --INSERT INTO WKIS_ERROR_LOG(transaction_no, transaction_date, description, error_msg) 
          --VALUES (r_test.transaction_no, r_test.transaction_date, r_test.description, 'Not a Debit or a Credit'); 
         END IF; 

         END lOOP; 
      --IF(v_credit_check != v_debit_check) THEN 
      --ROLLBACK; 
      --INSERT INTO WKIS_ERROR_LOG(transaction_no, transaction_date, description, error_msg) 
      --VALUES (r_transaction.transaction_no, r_transaction.transaction_date, r_transaction.description, 'Not a Debit or a Credit'); 
      --END IF;  


END LOOP; 

END; 
/
+3

您已經清楚地註釋了某種或類似構造的「END」。只是簡化,簡化,簡化並逐塊添加代碼。 –

+2

我知道這需要花費時間,但格式化一些這樣的代碼非常值得花費時間。你已經開始,不要在聲明下排隊,在你的循環開始時沒有排列的End循環缺少縮進。一旦格式化,它很快就會清楚地表明,賈耶恩薩耶瓦爾的回答是正確的,並且在兩個末端循環之間沒有結束。 –

回答

1

對於您的BEGIN語句之一,我沒有看到END。您在第一個END LOOP語句後缺少END。

BEGIN 
FOR r_test IN c_new_trans LOOP 
         .... 
END LOOP; 
END; 
相關問題