Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2003
    Posts
    7

    Unanswered: perplexing pl/sql error!!

    create or replace procedure insertval as
    declare
    counter NUMBER :=100;
    begin
    for i in 1 .. counter loop
    insert into test values(i);
    end loop;
    end;
    /



    Warning: Procedure created with compilation errors.

    SQL> show errors
    Errors for PROCEDURE INSERTVAL:

    LINE/COL ERROR
    -------- -----------------------------------------------------------------
    2/1 PLS-00103: Encountered the symbol "DECLARE" when expecting one of
    the following:
    begin function package pragma procedure subtype type use
    <an identifier> <a double-quoted delimited-identifier> cursor
    form current external language
    The symbol "begin" was substituted for "DECLARE" to continue.

    9/0 PLS-00103: Encountered the symbol "end-of-file" when expecting
    one of the following:
    begin declare end exception exit for goto if loop mod null
    pragma raise return select update while <an identifier>

    LINE/COL ERROR
    -------- -----------------------------------------------------------------
    <a double-quoted delimited-identifier> <a bind variable> <<
    close current delete fetch lock insert open rollback
    savepoint set sql execute commit forall
    <a single-quoted SQL string>



    but after i deleted "declare", it was ok!!
    anybody can tell me why i can't use declare here and when to use declare??


    many thanks!!

  2. #2
    Join Date
    Mar 2002
    Location
    Reading, UK
    Posts
    1,137
    declare is for anonymous plsql blocks not for procedures or functions. See the PLSQL manual.

    Alan

  3. #3
    Join Date
    Sep 2002
    Location
    Austria
    Posts
    37

    Re: perplexing pl/sql error!!

    to be a bit more precise: ...

    SQL> drop table test;

    Tabelle wurde gel÷scht.

    SQL> create table test (nr integer);

    Tabelle wurde angelegt.

    SQL>
    SQL>
    SQL> create or replace procedure insertval as
    2 counter NUMBER :=100;
    3 i pls_integer;
    4 begin
    5 for i in 1 .. counter loop
    6 insert into test values(i);
    7 end loop;
    8 end insertval;
    9 /

    Prozedur wurde angelegt.

    SQL> show errors;
    Keine Fehler.
    SQL>
    SQL> execute insertval;

    PL/SQL-Prozedur wurde erfolgreich abgeschlossen.

    SQL>
    SQL> select count(*) from test;

    COUNT(*)
    ----------
    100

    SQL>
    SQL> drop table test;

    Tabelle wurde gel÷scht.

    SQL>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •