0
votes

why it does not work ? i run this in oracle . i want to create aprocedure like that:

CREATE OR REPLACE PROCEDURE ME( X in NUMBER )IS  
declare 
num1 number;
BEGIN  
num1:=1;
insert into a (year) values(7);    
END; 

this is the error:

PLS-00103: Encountered the symbol "DECLARE" when expecting one of the following: begin function pragma procedure subtype type current cursor delete exists prior external language The symbol "begin" was substituted for "DECLARE" to continue. 7/5 PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: ( begin case declare end exception exit for goto if loop mod null pragma raise return select update while with << continue close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe purge

2

2 Answers

4
votes

DECLARE is only used in anonymous PL/SQL blocks and nested PL/SQL blocks. You wouldn't use it when you're declaring a procedure. Assuming the table A exists with a column YEAR, something like

CREATE OR REPLACE PROCEDURE ME( X in NUMBER )
IS  
  num1 number;
BEGIN  
  num1:=1;
  insert into a (year) values(7);    
END; 

is syntactically valid. Of course, there are all sorts of issues with the code... You take a parameter that you don't use, you declare a local variable that you don't use, the name of the procedure has no relation to what the procedure does, etc.

1
votes

Try as

    CREATE OR REPLACE PROCEDURE me (x IN NUMBER)
IS
    num1     NUMBER;
BEGIN
    num1 := 1;    
    insert into a (year) values(7);     
END;
/