DBMS Record For Degree Students
DBMS Record For Degree Students
DBMS Record For Degree Students
CERTIFICATE
Examiners:
1)
2)
INDEX
SL.NO NAME OF THE EXPERIMENT PAGE NO
1 SHIPMENT DATABASE
2 UNIVERSITY DATABASE
3 EMPLOYEE DATABASE
PL/SQL
4 PROGRAMTO PRINT THE MULTIPLICATION TABLE
8 PRINT HRA,DA,INSURANCE,INCOMETAX,GROSS
SALARY OF THE GIVEN EMPLOYEE NUMBER
9 PROGRAM TO PRINT THE NATURAL NUMBERS ANDITS
SUM
CREATING A DATABASE:
SQL> / create table sailors( sailor_id number(2) primary key, sailor_name char(10),
sailor_rating number(3));
Table created.
SQL> create table boats (boat_id number(3) primary key, boat_name char(10), boat_color
char(4));
Table created.
SQL> create table reserves (sailor_id number(2) primary key, boat_id number(3), day
char(10));
Table created.
DEFINITION OF THE DATABASE:
SQL> /
Enter value for sailor_id: 2
Enter value for sailor_name: ramana
Enter value for sailor_rating: 67
Enter value for sailor_age: 32
old 1: insert into sailors values('&sailor_id','&sailor_name','&sailor_rating','&sailor_age')
new 1: insert into sailors values('2','ramana','67','32')
1 row created.
SQL> /
Enter value for sailor_id: 3
Enter value for sailor_name: krishna
Enter value for sailor_rating: 45
Enter value for sailor_age: 34
old 1: insert into sailors values('&sailor_id','&sailor_name','&sailor_rating','&sailor_age')
new 1: insert into sailors values('3','krishna','45','34')
1 row created.
SQL> select * from sailors;
SAILOR_ID SAILOR_NAM SAILOR_RATING SAILOR_AGE
--------- - ---------- ------------- ----------
1 raju 45 26
2 ramana 67 32
3 krishna 45 34
SQL> /
Enter value for boat_id: 12
Enter value for boat_name: king
Enter value for boat_color: blue
old 1: insert into boats values('&boat_id',' &boat_name','&boat_color');
new 1: insert into boats values('12’,' king','blue');
1 row created.
SQL> /
Enter value for boat_id: 13
Enter value for boat_name: mantri
Enter value for boat_color: yellow
old 1: insert into boats values('&boat_id',' &boat_name','&boat_color');
new 1: insert into boats values('13’,' mantri','yellow');
1 row created.
SQL> select * from boats;
BOAT_ID BOAT_NAME BOAT_C
---------- ---------- ------
11 queen red
12 king blue
13 mantri yellow
SQL> /
Enter value for sailor_id: 2
Enter value for boat_id: 12
Enter value for day: monday
old 1: insert into reserves values('&sailor_id', '&boat_id','&day')
new 1: insert into reserves values('2', '12','monday')
1 row created.
SQL> /
Enter value for sailor_id: 3
Enter value for boat_id: 13
Enter value for day: tuesday
old 1: insert into reserves values('&sailor_id', '&boat_id','&day')
new 1: insert into reserves values('3', '13','tuesday')
1 row created.
SQL> select * from reserves;
QUERIES:
1) Find the name of the sailors who have reserver bost number 12
SQL> select s.sailor_name from sailors s, reserves r where s.sailor_id = r.sailor_id
and r.boat_id =12;
SAILOR_NAM
----------
Ramana
4) Find the names of the sailors who have reserved at least one boat
SQL>select s.sailor_name from sailors s , reserves r where s.sailor_id = r.sailor_id;
SAILOR_NAM
----------
Raju
Ramana
Krishna
CREATING A DATABASE
SQL>create tab le student (snum number(5) primary key, sname char(10), major
char(10), levchar(10), age number(2));
Table created.
SQL>create table class (cname char(10) primary key, meet number(3), room
number(4), fid number(5));
Table created.
Table created.
Table created.
DEFINITION OF THE DATABASE:
1 row created.
SQL> /
Enter value for snum: 102
Enter value for sname: kumari
Enter value for major: n
Enter value for lev: jr
Enter value for age: 17
old 1: insert into student values('&snum','&sname','&major','&lev','&age')
new 1: insert into student values('102','kumari','n','b','17')
1 row created.
SQL> /
Enter value for snum: 103
Enter value for sname: lavanya
Enter value for major: y
Enter value for lev: sr
Enter value for age: 20
old 1: insert into student values('&snum','&sname','&major','&lev','&age')
new 1: insert into student values('103','lavanya','y','b','20')
1 row created.
1 row created.
SQL> /
Enter value for cname: bcom
Enter value for meet: 9
Enter value for room: 7
Enter value for fid: 203
old 1: insert into class values('&cname','&meet','&room','&fid')
new 1: insert into class values('bcom','9','7','203')
1 row created.
SQL> /
Enter value for cname: ba
Enter value for meet: 8
Enter value for room: 3
Enter value for fid: 204
old 1: insert into class values('&cname','&meet','&room','&fid')
new 1: insert into class values('ba','8','3','204')
1 row created.
SQL> /
Enter value for snum: 103
Enter value for cname: bcom
old 1: insert into enrolled values('&snum','&cname')
new 1: insert into enrolled values('103','bcom')
1 row created.
SNUM CNAME
---------- ----------
101 bsc
102 bsc
103 bcom
1 row created.
SQL> /
Enter value for fid: 203
Enter value for fname: harsha
Enter value for depfid: 2
old 1: insert into faculty values('&fid','&fname','&depfid')
new 1: insert into faculty values('203','harsha','2')
1 row created.
SQL> /
Enter value for fid: 204
Enter value for fname: gayatri
Enter value for depfid: 3
old 1: insert into faculty values('&fid','&fname','&depfid')
new 1: insert into faculty values('204','gayatri','3')
1 row created.
QUERIES:
1) Print the level and the average age of students for that level for each level
LEV AVG(S.AGE)
---------- ----------
a 26
b 18.5
2) Find the names of students who are not enrolled is any class
SQL> select sname from student where snum not in (select snum from enrolled)
SNAME
----------
Laya
3) Find the names of all juniors who are enrolled in a class taught by gayatri
SQL>select s.sname from student s,class c, enrolled e,faculty f where s.snum = e.snum and
e.cname = c.cname and c.fid = f.fid and f.fname ='gayatri' and s.lev ='jr'
no rows selected
FNAME
----------
Ramana
5) Print the level and the average of students for that level for all levels except jr
SQL> select s.lev,avg(s.age) from student s where s.lev <> 'jr' group by lev
LEV AVG(S.AGE)
---------- ----------
a 26
b 18.5
EMPLOYEE DATABASE
EMPLOYEE (ssn,fname,lname,dob,add,sal,comm.,dno);
DEPARTMENT (dno,dname,loc);
CREATING A DATABASE
SQL>create table employee (ssn number(4) primary key, fname char(10), lname char(10), dob
date, ad varchar2(10), sal number(5,2), comm number(5), dno number(5) references
department);
Table created.
SQL>create table department(dno number(5) primary key, dname char(10), loc char(5));
Table created.
1 row created.
SQL> /
Enter value for dno: 2
Enter value for dname: synergies
Enter value for loc: kkd
old 1: insert into department values('&dno','&dname','&loc')
new 1: insert into department values('2','synergies','kkd')
1 row created.
SQL> /
Enter value for dno: 3
Enter value for dname: diamond
Enter value for loc: gwk
old 1: insert into department values('&dno','&dname','&loc')
new 1: insert into department values('3','diamond','gwk')
1 row created.
1 row created.
SQL> /
Enter value for ssn: 12
Enter value for fname: swathi
Enter value for lname: lanka
Enter value for dob: 24-jun-1991
Enter value for ad: gwk
Enter value for sal: 10000
Enter value for comm:
Enter value for dno: 2
old 1: insert into employee values('&ssn','&fname','&lname','&dob','&ad','&sal','&comm','&dno')
new 1: insert into employee values('12','swathi','lanka','24-jun-1991','gwk','10000','','2')
1 row created.
SQL> /
Enter value for ssn: 13
Enter value for fname: ranga
Enter value for lname: kanti
Enter value for dob: 27-apr-1994
Enter value for ad: mvp
Enter value for sal: 20000
Enter value for comm: 400
Enter value for dno: 3
old 1: insert into employee values('&ssn','&fname','&lname','&dob','&ad','&sal','&comm','&dno')
new 1: insert into employee values('13','ranga','kanti','27-apr-1994','mvp','20000','400','3')
1 row created.
QUERIES:
2 rows updated
2) Print the name and address of all employees who work for the department computers
FNAME AD
---------- ----------
Krishna mvp
Ranga mvp
SQL> select * from emp where sal = ( select max(sal) from employee)
SSN sum(sal+comm)
---------- ----------
11 21000
12 10000
13 21000
6) Print the name of the employee whose salary between 10000 and 20000
SQL> select fname from employee where sal between 10000 and 20000;
FNAME
----------
Krishna
Swathi
Ranga
1 row deleted
8) Print the details of the employee whose name start with the letter ‘s’
9) Write a query to add new field phone number into the table employee
Table altered.
10) Print the name of the employee whose date of birth 27-apr-94
SQL> select * from employee where dob =’27-apr-1994’;
declare
n number(2);
i number(2);
s number(2);
begin
n := &n;
dbms_output.put_line(' The Multiplication table for ' || n);
for i in 1 .. 12
loop
s := n * i;
dbms_output.put_line(n || '*' || i || '=' || s);
end loop;
end;
OUTPUT:
SQL> /
2*1=2
2*2=4
2*3=6
2*4=8
2*5=10
2*6=12
2*7=14
2*8=16
2*9=18
2*10=20
2*11=22
2*12=24
declare
n number(2);
a number(2) := 0;
b number(2) := 1;
c number(2);
i number(2);
begin
n := &n;
dbms_output.put_line(' The fibonacci series is ' );
dbms_output.put_line(a);
dbms_output.put_line(b);
for i in 1 .. (n -2)
loop
c := a+b;
dbms_output.put_line(c);
a:=b;
b:=c;
end loop;
end;
OUTPUT:
SQL> /
declare
e emp%rowtype;
begin
select * into e from emp where empno = &empno;
dbms_output.put_line('Employee Number : ' || e.empno);
dbms_output.put_line('Employee Name : ' || e.ename);
dbms_output.put_line('Employee Salary : ' || e.sal);
dbms_output.put_line('Employee Job : ' || e.job);
end;
OUTPUT:
SQL> /
Enter value for empno: 7369
old 4: select * into e from emp where empno = &empno;
new 4: select * into e from emp where empno = 7369;
Employee Number : 7369
Employee Name : SMITH
Employee Salary : 800
Employee Job : CLERK
declare
e emp.job%type;
begin
select job into e from emp where empno=&empno;
if(e='CLERK') then
update emp set sal = sal+800;
end if;
end;
OUTPUT:
SQL> /
Enter value for empno: 7369
old 4: select job into e from emp where empno=&empno;
new 4: select job into e from emp where empno=7369;
declare
sal number;
hra number;
da number;
insur number;
intax number;
gs number;
begin
select sal into sal from emp where empno='&empno';
hra := sal * 15/100;
da := sal * 12/100;
intax := sal * 10/100;
insur := sal * 10/100;
gs := (sal + hra + da) - (intax+insur);
dbms_output.put_line('Basic Salary: ' ||sal);
dbms_output.put_line('HRA : ' ||hra);
dbms_output.put_line('DA : ' ||da);
dbms_output.put_line('Insurance: ' ||insur);
dbms_output.put_line('Income Tax : ' ||intax);
dbms_output.put_line('Gross Salary: ' ||gs);
end;
OUTPUT :
SQL> /
Enter value for empno: 7369
old 9: select sal into sal from emp where empno='&empno';
new 9: select sal into sal from emp where empno='7369';
Basic Salary: 800
HRA : 120
DA : 96
Insurance: 80
Income Tax : 80
Gross Salary: 856
declare
n number;
i number;
s number := 0;
begin
n:=&n;
dbms_output.put_line('The natural numbers are');
for i in 1..n
loop
dbms_output.put_line(i);
s:=s+i;
end loop;
dbms_output.put_line('The sum of '|| n || 'natural numbers is ' || s);
end;
OUTPUT:
SQL> /
Enter value for n: 10
old 6: n:=&n;
new 6: n:=10;
The natural numbers are
1
2
3
4
5
6
7
8
9
10
The sum of 10 natural numbers is 55
declare
a number;
b number;
begin
a:=&a;
b:=&b;
dbms_output.put_line('Before Swapping');
dbms_output.put_line('a:= ' || a);
dbms_output.put_line('b:= ' || b);
a:=a+b;
b:=a-b;
a:=a-b;
dbms_output.put_line('After Swapping');
dbms_output.put_line('a:= ' || a);
dbms_output.put_line('b:= ' || b);
end;
OUTPUT:
SQL> /
Enter value for a: 10
old 5: a:=&a;
new 5: a:=10;
Enter value for b: 20
old 6: b:=&b;
new 6: b:=20;
Before Swapping
a:= 10
b:= 20
After Swapping
a:= 20
b:= 10
declare
n number(2);
r number(2);
s number(2) := 0;
i number(2) := 1;
m number(2);
begin
n:= &n;
m:=n;
while (i<n)
loop
r:=mod(n,i);
if (r = 0) then
s := s+i;
end if;
i:=i+1;
end loop;
if(m = s) then
dbms_output.put_line('The given number is strong number');
else
dbms_output.put_line('The given number is not a strong number');
end if;
end;
OUTPUT :
SQL> /
Enter value for n: 6
old 8: n:= &n;
new 8: n:= 6;
The given number is strong number
SQL> /
Enter value for n: 5
old 8: n:= &n;
new 8: n:= 5;
The given number is not a strong number
declare
n number(3);
r number(3);
s number(3) := 0;
m number(3);
begin
n := &n;
m := n;
while(n != 0)
loop
r := mod(n,10);
s:= r+s*10;
n:=n/10;
end loop;
dbms_output.put_line('The reverse of a given number is ' || s);
if (m = s) then
dbms_output.put_line('The given number is palindrome');
else
dbms_output.put_line('The given number is not a palindrome');
end if;
end;
OUTPUT:
SQL> /
Enter value for n: 123
old 7: n := &n;
new 7: n := 123;
The reverse of a given number is 321
The given number is not a palindrome
OUTPUT:
SQL> /
Enter value for n: 232
old 7: n := &n;
new 7: n := 232;
The reverse of a given number is 232
The given number is palindrome
declare
n number(2);
r number(2);
e number(2) := 0;
o number(2) := 0;
m number(2);
begin
n:= &n;
m:= &m;
for i in n .. m
loop
r:= mod(n,2);
if (r = 0) then
e:= e+i;
else
o:= o+i;
end if;
end loop;
dbms_output.put_line('The sum of even numbers between the range ' || e);
dbms_output.put_line('The sum of odd numbers between the range' || o);
end;
OUTPUT:
SQL> /
Enter value for n: 20
old 8: n:= &n;
new 8: n:= 20;
Enter value for m: 30
old 9: m:= &m;
new 9: m:= 30;
The sum of even numbers between the range 150
The sum of odd numbers between the range 125
declare
a number(2);
b number(2);
c number(2);
begin
a:=&a;
b:=&b;
c:=&c;
if ((a>b) and (a>c)) then
dbms_output.put_line(a || 'is biggest');
else if ((b>a) and (b>c)) then
dbms_output.put_line(b || 'is biggest');
else
dbms_output.put_line(c || 'is biggest');
end if;
end if;
end;
OUTPUT:
SQL> /
Enter value for a: 10
old 6: a:=&a;
new 6: a:=10;
Enter value for b: 30
old 7: b:=&b;
new 7: b:=30;
Enter value for c: 20
old 8: c:=&c;
new 8: c:=20;
30 is biggest
declare
s e%rowtype;
nunits number(4);
amount number(8,2);
ser number(8,2);
bill number(8,2);
begin
select * into s from e where mno = &mno;
dbms_output.put_line('Consumer number : '||s.mno);
dbms_output.put_line('Consumer name : '||s.cname);
dbms_output.put_line('Current Reading : '||s.cur_read);
dbms_output.put_line('Prevoius Reading : '||s.prev_read);
nunits := s.cur_read - s.prev_read;
dbms_output.put_line('Number of units : '||nunits);
if (nunits <= 100) then
amount := nunits *0.45;
else if ((nunits >100 ) and (nunits <= 300)) then
amount := (100 *0.45) + (nunits -100) *1;
else if ((nunits >300 ) and (nunits <= 700)) then
amount := (100 *0.45) + (200 *1) + (nunits -300) *2;
else if ((nunits >700 ) and (nunits <= 1000)) then
amount := (100 *0.45) + (200*1) +(300 *2) +(nunits -700) *4;
else if (nunits > 1000) then
amount := (100 *0.45) + (200*1) +(300 *2) +(700 *4)+(nunits -
1000) *5;
end if;
end if;
end if;
end if;
end if;
dbms_output.put_line('Amount : '|| amount);
ser := amount *10/100;
dbms_output.put_line('Service Tax: '|| ser);
bill := amount +ser;
dbms_output.put_line('Bill Amount : '|| bill);
end;
OUTPUT :
SQL> /
Enter value for mno: 1
old 8: select * into s from e where mno = &mno;
new 8: select * into s from e where mno = 1;
Consumer number : 1
Consumer name : krishna
Current Reading : 3456
Prevoius Reading : 1234
Number of units : 2222
Amount : 9755
Service Tax: 975.5
Bill Amount : 10730.5
declare
s std%rowtype;
t number(4);
g char(1);
av number(4);
begin
select * into s from std where no = &no;
t := s.m1+s.m2+s.m3;
av := t/3;
if ((s.m1<35 ) and (s.m2<35) and (s.m3<35)) then
g:= 'F';
else if (av >= 75) then
g := 'A';
else if ((av < 75) and (av >= 60)) then
g := 'B';
else if ((av < 60) and (av >= 50)) then
g := 'C';
else if ((av < 50) and (av >= 35)) then
g := 'D';
end if;
end if;
end if;
end if;
end if;
insert into abstract values(s.no,s.name,s.class,t,av,g);
commit;
end;
OUTPUT:
NO NAME CLAS M1 M2 M3
----- ---------- ---- ---------- ---------- ----------
1 lavanya bsc 56 78 90
2 gayatri msc 32 56 78
SQL> /
Enter value for no: 1
old 7: select * into s from std where no = &no;
new 7: select * into s from std where no = 1;
SHIPMENT DATABASE
1
UNIVERSITY DATABASE
2
EMPLOYEE DATABASE
3
Program for multiplication table
4
Program for biggest of two numbers
5
Program for Natural numbers and its sum
6
Program to swap the numbers without using third variable
7
Program for Strong Number
8
Program for palindrome
9
Program for sum of even & odd numbers in the given range
10
Program for Fibonacci series
11
Program to print the employee details from emp table
12
Program to update the salary of the given employee
13
Program for allowances for the given employee
14
Program to generate current bill
15
Program to find the tot,avg,grade and store in another table
16