B SC III Sem DBMS Record Programs
B SC III Sem DBMS Record Programs
SQL Programs
PL/SQL Programs
Problem 1: -
Procedure:-
E-R Diagram:-
Problem 2: -
Procedure: -
E-R Diagram: -
Problem 3: -
Creation of college database and establish relationships between tables
Procedure: -
Table Creation: -
1) Find the names of all juniors (Level=Jr) who are enrolled in a class taught by ‘Smith’.
SQL> Select Distinct(Sname) From Student,Faculty,Class,Enrolled where Faculty.Fid=Class.Fid and
Class.Cname=Enrolled.Cname and Enrolled.Snum=Student.Snum and Level1='Jr' and
Fname='Smith';
SNAME
----------
aa
bb
2) Print the level and Average Age of the Students for that level for each level.
SQL> Select Distinct(Level1),Avg(Age) From Student Group By Level1;
LEV AVG(AGE)
------ ---------
S V Degree College Page-7
II B SC (DBMS Record Programs)
Jr 19
Sr 21
SSr 22
3) Print the level and Average Age of the Students for that level, for all levels except juniors.
SQL> Select Distinct(Level1),Avg(Age) From Student Group By Level1 Having Level1!='Jr';
LEV AVG(AGE)
------ -------------
Sr 21
SSr 22
4) Find the names of the Student who are not enrolled in any class.
SQL> Select Distinct(Sname) From Student,Enrolled Where Student.Snum not in (Select
Enrolled.Snum from Enrolled);
SNAME
----------
cc
dd
Problem 4: -
Write a view to extract details from two or more tables.
Procedure: -
SQL> Create Table Dept (Deptno number(2) Primary Key, Dname varchar2(10));
DEPTNO DNAME
------------ -----------
10 Accounting
20 Marketing
30 Finance
40 Sales
Create Table Employee (Empno number(4) Primary Key, Ename varchar2(10), Job varchar2(10), Hiredate
date, Sal number(7,2),deptno number(2) references dept(deptno) );
Creating View: -
Procedure: -
Table Creation: -
SQL> Create Table Employees (Empno number(4) Primary Key, Ename varchar2(10), Job varchar2(10),
Hiredate date, Sal number(7,2));
Aggregate functions: -
Output: 4
Output: 52000
Output: 13000
Output: 16000
Output: 10000
Problem 6: -
Creation of Reports based on different queries
Procedure : -
Table Creation: -
SQL> Create Table Emp (Empno number(4) Primary Key, Ename varchar2(10), Job varchar2(10), Hiredate
date, Sal number(7,2));
1) List All Employees Names and their Salaries, Whose Salary lies between 12000/- and 16000/- both
inclusive.
SQL> Select Ename,Sal From Emp Where Sal between 12000 and 16000;
ENAME SAL
---------- ----------
Ramesh 16000
Rajesh 12000
Naveen 14000
SQL> Select Ename From Emp where Ename like 'P%' or Ename like 'S%';
ENAME
Sudheer
Manager
Salesman
SQL> Select Min (Sal), Max (Sal), Avg (Sal) From Emp;
Problem 7: -
Declare
R number;
S number:=0;
N number;
Temp number;
Begin
N :=&number;
Temp:=n;
While N > 0 loop
R:=mod(N,10);
S:=S+(R*R*R);
N:=floor(N/10);
End loop;
If S=Temp then
Dbms_output.put_line(‘The Given Number is an Armstrong Number’);
Else
Dbms_output.put_line(‘The Given Number is Not an Armstrong Number’);
End if;
End;
/
Output:
Problem 8: -
pl/sql program to check the given number is a palindrome or not.
Declare
X number;
Rev number;
N number;
Temp number;
Begin
N :=#
Rev :=0;
Temp:=N;
While N>0 loop
X:=mod(N,10);
Rev :=(Rev*10)+X;
N:=floor(N/10);
End loop;
If Temp=Rev then
Dbms_output.put_line(‘The given number is a palindrome number’);
Else
Dbms_output.put_line(‘The given number is not a palindrome number’);
End if;
End;
/
Output:
Problem 9: -
pl/sql program to generate multiplication of tables for 2, 4,6.
Declare
I number;
J number;
Begin
I :=2;
While i<=6 loop
For j in 1..10 loop
Dbms_output.put_line(I||’ ‘||’*’||’ ‘||J||’ ‘||’=’||I*J);
End loop;
I:=I+2;
Dbms_output.put_line(‘------------‘);
End loop;
End;
/
Output:
Problem 10: -
Write a stored procedure to process student’s results.
Procedure: -
Table Creation:-
PL/SQL program:-
Output:
Problem 11: -
Creating Function: -
Calling Function: -
DECLARE
n3 number(2);
BEGIN
n3 := adder(11,22);
dbms_output.put_line('sum of two numbers =: ' || n3);
END;
/
Output:
Procedure : -
OUTPUT:-
SQL> select * from emp;