简体   繁体   中英

stored procedure in oracle 11g

create procedure p5(age1 IN number) as
     BEGIN
     if age1>18 then 
         insert into t values ( age1 );
     else
         dbms_output.putline('age should be high');
     end if;
end p5;

Warning: Procedure created with compilation errors.

I have tried executing this and i am getting errors listed below

SQL> exec p5(20);
BEGIN p5(20); END;
     *
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00905: object SYSTEM.P5 is invalid
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

I am still getting these errors

There are multiple problems,

create or replace procedure p3(age1 IN number) as --you dont need (3) here. Also closing braces are missing.
     BEGIN
     if age1>18 then 
         insert into t values ( age1 );
     else
         dbms_output.put_line('age should be high'); --you were using putline.
     end if;
end p3;  --your proc name is p2 but you are endin p3. Not needed. Just END will also do.

I tried running it locally and it is working fine.

create table t (age number(3));

Table T created.

create procedure p3(age1 IN number) as 
 BEGIN
 if age1>18 then 
     insert into t values ( age1 );
 else
     dbms_output.put_line('age should be high');
 end if;
end p3;

Procedure P3 compiled

set serveroutput on;

exec p3(23);

PL/SQL procedure successfully completed.

exec p3(17);

PL/SQL procedure successfully completed.

age should be high

select * from t;

AGE
23

The error is here:

dbms_output.put_line

instead of

dbms_output.putline

You missed closing parenthesis after p3(age1 IN number(3) . Try following :

create procedure p3(age1 IN number) as
     BEGIN
     if age1>18 then 
         insert into t values ( age1 );
     else
         dbms_output.put_line('age should be high');  -- it should be put_line
     end if;
end p3;  --correct procedure name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM