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

Lab 6 PL-SQL-Procedure

Uploaded by

aryan.desai23
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Lab 6 PL-SQL-Procedure

Uploaded by

aryan.desai23
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

1] Simple Procedure displaying Message

delimiter $$
drop procedure if exists display$$
create procedure display()
begin
select "My first program" as "Output";
end $$
delimiter ;

• When you write an individual statement you will need only a semicolon at the end
of the statement.

• But what if you want to write a block of statements that works as a single unit? In
that case, you will need to change the delimiter.

• In MySQL, stored procedures, functions and triggers are the blocks of statements
where you need the delimiter other than the default semicolon. The delimiter helps
MySQL to acknowledge the group of statements as a single unit or single task.
However, the individual statements in the blocks end with semicolons.

• If you are considering multiple statements, then you need to use different
delimiters like $$ or //.

2] Procedure to display value of variable


delimiter $$
drop procedure if exists display$$
create procedure display()
begin
declare X int;
set X=10;
select X;
end $$

3] Procedure to display addition of two numbers


Delimiter $$
Drop procedure if exists addition$$
Create procedure addition()
Begin
Declare a,b ,c int;
Set a=10;
Set b=10;
Set C=a+b;
Select c;
End $$

4] Procedure to display all records of table


delimiter $$
drop procedure if exists faculty_display $$
create procedure faculty_display()
begin
select * from faculty ;
end $$
delimiter ;
5] Procedure to display particular record of table through parameter passing
delimiter $$
drop procedure if exists emp_display $$
create procedure emp_display (IN X int)
begin
select * from emp where emp_id =X ;
end $$
delimiter ;

6] Procedure to display NO.of employees through procedure


delimiter $$
drop procedure if exists display $$
create procedure display (OUT cnt int)
begin
select count(emp_nm) as no_of_Employees from emp where emp_nm in(select distinct
emp_nm from emp);
end $$
delimiter ;
setp1 : execute this procedure
step 2: call the procedure in bracket specify @ sign with any parameter name . For
example:call display(@a);
step 3: if does not get outout then use query as select name of parameter For ex: select a

7] Procedure to display NO.of different departments through procedure


delimiter $$
drop procedure if exists display $$
create procedure display (OUT cnt int)
begin
select count(distinct emp_dept)as no_of_department from emp;
end $$
delimiter ;

You might also like