Example 1:: Create (Or Replace) Procedure Procedurename (Parameters) Is Begin End Procedurename
Example 1:: Create (Or Replace) Procedure Procedurename (Parameters) Is Begin End Procedurename
end procedurename;
Example 1:
create or replace procedure my_first_proc is
greetings varchar2(20);
begin
greetings := 'Hello World';
dbms_output.put_line(greetings);
end my_first_proc;
To run the my_first_proc:
1. execute my_first_proc;
2. begin
my_first_proc;
end;
Example 2:
create or replace procedure my_second_proc is
begin
update student set age=29 where sno=1201;
end my_second_proc;
create or replace procedure my_second_proc (no number) is
begin
update student set age=29 where sno=no;
end my_second_proc;
create or replace procedure my_second_proc (no in number) is
begin
update student set age=29 where sno=no;
end my_second_proc;
To run my_second_proc:
1. execute my_second_proc;
2. begin
my_second_proc(1201);
end
Example 3:
create or replace procedure my_third_proc (i number) is
greetings varchar2(20);
j number;
begin
greetings := 'Hello World';
dbms_output.put_line(greetings);
j := i;
dbms_output.put_line(j);
end my_third_proc;
To run my_third_proc:
1. execute my_first_proc(10);
2. begin
my_first_proc(10);
end;
Example 4:
create or replace procedure FindStudent(I_sno in number,O_sname out varchar2,O_branch out
varchar2) is
begin
select sname,branch into O_sname,O_branch FROM student WHERE sno = I_sno;
dbms_output.put_line(O_sname|| ||O_branch);
exception when no_data_found then
dbms_output.put_line('Error in Finding the Details of Employee Number :'||I_sno);
end FindStudent;
Example 5:
create or replace procedure studentInsert(
v_sno student.sno%TYPE,
v_sname student.sname%TYPE,
v_branch student.branch%TYPE,
v_age student.age%TYPE) Is
begin
insert into student(sno,sname,branch,age)values(v_sno,v_sname,v_branch,v_age);
commit;
end studentInsert;
To run studentInsert procedure:
declare
begin
studentInsert(1222,'sreenu','it',28);
end;