2016-06-26 353 views
1

我收到錯誤,如:錯誤:00103的PLSQL過程

Error(5,1): PLS-00103: Encountered the symbol "DECLARE" when expecting one of the following: begin function pragma procedure subtype type <an identifier> <a double-quoted delimited-identifier> current cursor delete exists prior external language The symbol "begin" was substituted for "DECLARE" to continue.

Error(5,1): PLS-00103: Encountered the symbol "DECLARE" when expecting one of the following: begin function pragma procedure subtype type <an identifier> <a double-quoted delimited-identifier> current cursor delete exists prior external language The symbol "begin" was substituted for "DECLARE" to continue.

,我的代碼是:

CREATE OR REPLACE PROCEDURE procExplicitCursorAccountSlct 
AS 
DECLARE 
    CURSOR C1 IS SELECT * FROM ACCOUNT; 
BEGIN 
    OPEN C1; 
    FOR i in C1 LOOP 
    FETCH C1 INTO ID,ACCOUNTTYPE,BALANCE; 
    EXIT WHEN C1%NOTFOUND; 
    DBMS_OUTPUT.PUT_LINE(ID||'-'||ACCOUNTTYPE||'-'||BALANCE); 
    DBMS_OUTPUT.PUT_LINE(C1%ROWCOUNT); 
    END LOOP; 
    CLOSE C1;  
END; 
+2

只是刪除'DECLARE'關鍵字。請參閱CREATE PROCEDURE的語法:https://docs.oracle.com/database/121/LNPLS/create_procedure.htm#LNPLS01373 Threre在IS/AS關鍵字後面直接顯示* declre_section *,但本節不包含DECLARE關鍵字**。此關鍵字僅用於匿名塊和觸發器中。 – krokodilko

回答

1

試試這個,看看修改內部註釋。希望能幫助到你。

CREATE OR REPLACE 
PROCEDURE procExplicitCursorAccountSlct 
AS 
    CURSOR C1 
    IS 
    SELECT 
     * 
    FROM 
     ACCOUNT; 
--Variabke declaration was missing 
    ID   NUMBER; 
    ACCOUNTTYPE VARCHAR2(100); 
    BALANCE  NUMBER; 
    --Variabke declaration was missing 
BEGIN 
    OPEN C1; 
    LOOP 
    FETCH 
     C1 
    INTO 
     ID, 
     ACCOUNTTYPE, 
     BALANCE; 
    EXIT 
    WHEN C1%NOTFOUND; 
    DBMS_OUTPUT.PUT_LINE(ID||'-'||ACCOUNTTYPE||'-'||BALANCE); 
    DBMS_OUTPUT.PUT_LINE(C1%ROWCOUNT); 
    END LOOP; 
    CLOSE C1; 
END; 
0

你可以把它的方式更加簡單與隱含的循環(和刪除DECLARE太):

CREATE OR REPLACE PROCEDURE procExplicitCursorAccountSlct 
AS 
    CURSOR C1 IS SELECT * FROM ACCOUNT; 
BEGIN 
    FOR i in C1 LOOP 
    DBMS_OUTPUT.PUT_LINE(i.ID||'-'||i.ACCOUNTTYPE||'-'||i.BALANCE); 
    DBMS_OUTPUT.PUT_LINE(C1%ROWCOUNT); 
    END LOOP; 
END;