0% found this document useful (0 votes)
15 views8 pages

Programm of All Category

The document contains a series of PL/SQL programming exercises focused on various database management tasks, including condition checks, loops, and exception handling. It provides code snippets for determining even/odd numbers, eligibility for voting, finding factorials, generating Fibonacci series, and more. Additionally, it covers the creation of functions, procedures, packages, and triggers for database operations.

Uploaded by

vrajpatelmyindia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views8 pages

Programm of All Category

The document contains a series of PL/SQL programming exercises focused on various database management tasks, including condition checks, loops, and exception handling. It provides code snippets for determining even/odd numbers, eligibility for voting, finding factorials, generating Fibonacci series, and more. Additionally, it covers the creation of functions, procedures, packages, and triggers for database operations.

Uploaded by

vrajpatelmyindia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Ganpat University – BSPP & IOT

DATABASE MANAGEMENT SYSTEM – 1CE2401

************CONDITION & LOOPING PROGRAM************

1. Write a PL /SQL Block for find given no is even or odd.


declare
n number:=&n;
begin
if n MOD 2 = 0 then
Dbms_output.put_line('Given no is even');
else
Dbms_output.put_line('Given no is odd');
end if;
end;
/
2. Write a PL /SQL Block to check the person is eligible for voting or not.
declare
n number:=&n;
begin
if n >18 then
dbms_output.put_line('Eligible for votting');
else
dbms_output.put_line('Not Eligible for votting');
end if;
end;
/
3. Write a PL /SQL Block to find out greater number from given two no.
declare
a number:=&a;
b number:=&b;
begin
if a > b then
dbms_output.put_line('A is Greater No.');
else
dbms_output.put_line('B is Greater No.');
end if;
end;
/
4. Write a PL /SQL Block to find out greater number from given Three no.

declare

1
Ganpat University – BSPP & IOT
a number:=&a;
b number:=&b;
c number:=&c;
begin
if a > b then
if a > c then
dbms_output.put_line('A is Greater No.');
else
dbms_output.put_line('C is Greater No.');
end if;
else
if b > c then
dbms_output.put_line('B is Greater No.');
else
dbms_output.put_line('C is Greater No.');
end if;
end if;
end;
/

5. Write a Pl/SQL Block to find the factorial of given number.

declare
n number:=&n;
fact number(10):=1;
begin
while n>=1
loop
fact := fact*n;
n:=n-1;
end loop;
dbms_output.put_line('factorial = '||fact);
end;
/

6. Write a Pl/SQL Block to display the Fibonacci series.

declare
a number:=0;
b number:=1;
c number:=0;
begin
dbms_output.put_line(a);
dbms_output.put_line(b);
while c < 50
loop
c:=a +b;

2
Ganpat University – BSPP & IOT
dbms_output.put_line(c);
a:=b;
b:=c;
end loop;
end;
/

7. Write a PL/SQL block to display Series from 1 to 10.

declare
begin
for i in 1..10
loop
dbms_output.put_line(i);
end loop;
end;
/
8. Write a PL /SQL Block to convert given number to reverse no.
declare
n number:=&n;
r number;
rev number(10):=0;
m number;
begin
m:=n;
while n >0
loop
r:=n MOD 10;
rev :=rev*10 +r;
n:=floor(n/10);
end loop;
dbms_output.put_line('the reverse no is ='||rev);
end;
/
9. Write a PL /SQL Block to check the given number is palindrome no. or not.
declare
n number:=&n;
r number;
rev number(10):=0;
m number;
begin
m:=n;
while n >0
loop
r:=n MOD 10;
rev :=rev*10 +r;
n:=floor(n/10);

3
Ganpat University – BSPP & IOT
end loop;
if m = rev then
dbms_output.put_line('given no is palindrom');
else
dbms_output.put_line('given no is Not palindrom');
end if;
end;
/
10. Write a PL /SQL Block to check the given number is perfect no. or not.

declare
n number:=&n;
r number;
s number:=0;
m number:=1;
begin
while n >0
loop
r:=n MOD 10;
s:=s+r;
m:=m*r;
n:=n/10;
end loop;
if s =m then
dbms_output.put_line('perfact no');
else
dbms_output.put_line('not perfact no');
end if;
end;
/
11. Write a PL /SQL Block to check the given number is Armstrong no. or not.

declare
n number:=&n;
r number;
arm number(10):=0;
m number;
begin
m:=n;
while n >0
loop
r:=n MOD 10;
arm :=arm +(r*r*r);
n:=floor(n/10);
end loop;
if arm=m then
dbms_output.put_line('Given no is Armstrong');

4
Ganpat University – BSPP & IOT
else
dbms_output.put_line('Given no is Not Armstrong');
end if;
end;
/
**********EXCEPTION PROGRAM**********

12. Write a PL/SQL Block for Predefine Exception.


Declare
N number;
Begin
N:=10/0;
Exception
When ZERO_DIVIDE then
Dbms_output.put_line(‘Zero_Divide Error’);
End;
/
13. Write a PL/SQL Block for User define exception.
Declare
Myexception exception;
Begin
If to_char(sysdate, ‘dy’)= ‘SUN’ then
End if;
Exception
When myexception then
Dbms_output.put_line(‘no transaction today’);
End;
/
***************CURSOR PROGRAM****************

14. Write a PL/SQL Block For Implicit Cursor.


Declare
No number(10);
Begin
Update student set s_name =’ramesh’ where s_no =1;
No:=sql%rowcount;
If sql%found then
Dbms_output.put_line(‘success’);
Else
Dbms_output.put_line(‘Not success’);
End if;
Dbms_output.put_line(‘Row count:=’||no);
End;
/
15. Write a PL/SQL Block For Explicit Cursor.

Declare

5
Ganpat University – BSPP & IOT
Cursor er is select s_no , s_name from student;
No student.s_no%type;
Name student.s_name%type;
Begin
Open er;
Loop
Fetch er into no, name;
Exit when er%notfound;
Dbms_output.put_line(no||name);
End loop;
Close er;
End;
/

************FUNCTION , PROCEDURE & PACKAGE PROGRAM**********

16. Write a PL/SQL Block for Create Function.


create or replace function f1
return varchar2
is
name varchar2(20);
begin
select s_name into name from student where s_no =2;
return name;
end;
/

17. Write a Pl/SQL Block to create Procedure.


create or replace procedure p1(a number , b in out number)
as
begin
insert into t11 values(a,b);
end;
/

declare
v number;
begin
p1(200,v);
end;
/

18. Write a Pl/SQL Block to create Package.


(Package Specification)
create or replace package pkg1
as

6
Ganpat University – BSPP & IOT
function area(r number) return number;
procedure print(s1 varchar2:= 'hello',s2 varchar2:='india');
end;
/
(Package Body)
create or replace package body pkg1
as
function area(r number) return number
is
pi number :=3.14;
begin
return pi*(r**2);
end area;

procedure print(s1 varchar2:='hello', s2 varchar2:='india')


is
begin
dbms_output.put_line(s1||','||s2);
end print;
end pkg1;
/
************TIRGGER PROGRAM************

19. Create a Trigger for Insert.


Requirement :- Main table Student(s_no, s_name,Branch, Location)
Student_insert(s_no,s_name,brancj , location ,username)
create or replace trigger t1
AFTER INSERT
ON student
for each row
declare
v_username varchar2(10);
begin
select user into v_username from dual;
insert into student_insert values(:new.s_no,:new.s_name,:new.branch,:new.location,v_username);
end;
/

20. Create a Trigger for update.


Requirement :- Main table Student(s_no, s_name,Branch, Location)
Student_update(s_no,s_name, old_branch, new_branch ,username)

create or replace trigger t2 after update


on student
for each row
declare
v_username varchar2(10);

7
Ganpat University – BSPP & IOT
begin
select user into v_username from dual;
insert into student_update values(:new.s_no,:new.s_name,:old.branch,:new.branch,v_username);
end;
/
21. Create a Trigger for update.
Requirement :- Main table Student(s_no, s_name,Branch, Location)
Student_delete(s_no,s_name, old_branch, new_branch,username)
create or replace trigger t2 after update
on student
for each row
declare
v_username varchar2(10);
begin
select user into v_username from dual;
insert into student_update values(:new.s_no,:new.s_name,:old.branch,:new.branch,v_username);

22. Create a Trigger for delete.


Requirement :- Main table Student(s_no, s_name,Branch, Location)
Student_delete(s_no,s_name, branch, date ,username)

create or replace trigger t3 before delete


on student
for each row
declare
v_username varchar2(10);
begin
select user into v_username from dual;
insert into student_delete values(:old.s_no,:old.s_name,:old.branch,sysdate,v_username);
end;
/

************ALL THE BEST**************

You might also like