0% found this document useful (0 votes)
48 views

Example 1:: Create (Or Replace) Procedure Procedurename (Parameters) Is Begin End Procedurename

The document provides examples of how to create procedures in Oracle SQL. It demonstrates creating basic procedures without parameters and with IN, OUT, and IN/OUT parameters. Examples show how to call procedures, handle exceptions, and commit transactions. Procedures allow reusable blocks of SQL code and logic to be stored in the database for repeated execution.

Uploaded by

Lalith Kartikeya
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Example 1:: Create (Or Replace) Procedure Procedurename (Parameters) Is Begin End Procedurename

The document provides examples of how to create procedures in Oracle SQL. It demonstrates creating basic procedures without parameters and with IN, OUT, and IN/OUT parameters. Examples show how to call procedures, handle exceptions, and commit transactions. Procedures allow reusable blocks of SQL code and logic to be stored in the database for repeated execution.

Uploaded by

Lalith Kartikeya
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Procedure Syntax:

create [or replace] procedure procedurename (parameters) is


begin

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;

To run above procedure:


declare
V_sname student.sname%TYPE;
V_branch student.branch%TYPE;
begin
FindStudent(1201, V_sname, V_branch);
end;

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;

You might also like