PALAK
PALAK

Reputation: 11

error:00103 for plsql procedure

I am getting error such as:

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.

and my code is:

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;

Upvotes: 1

Views: 10575

Answers (2)

J. Chomel
J. Chomel

Reputation: 8395

You could make it way more simple with implicit loop (and removing DECLARE too):

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;

Upvotes: 0

Avrajit Roy
Avrajit Roy

Reputation: 3303

Try this and see inline comments for modifications. Hope it helps.

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;

Upvotes: 2

Related Questions