Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

DBMS Record For Degree Students

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 53

NEWS DEGREE COLLEGE

(Affiliated to Andhra University)


GAJUWAKA,VISAKHAPATNAM-26
****************************************************************

DEPARTMENT OF COMPUTER SCIENCE

Regd No: ______________________

CERTIFICATE

This is to certify that the bonafied record of Practical work


done in DBMS by Mr/Miss ______________________________________
a student of III YEAR B.Sc., Computer Science of this college during the
year 2016– 2017.

Total No.of Programs: ___________

No.of Programs done : ___________

Lecturer in charge Head of the Department

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

5 PROGRAMTO PRINT THE FIBONACCISERIES

6 PROGARMTO PRINT THE EMPLOYEE DETAILS FROM


THE EMP TABLE

7 PROGARMTO UPDATE SALARY OF THE GIVEN


EMPLOYEE

8 PRINT HRA,DA,INSURANCE,INCOMETAX,GROSS
SALARY OF THE GIVEN EMPLOYEE NUMBER
9 PROGRAM TO PRINT THE NATURAL NUMBERS ANDITS
SUM

10 PROGRAM TP SWAPTHE NUMBERS WITH OUT USING


THIRD VARIABLE

11 PROGRAM TO FIND GIVEN NUMBER IS STRONG


NUMBER OR NOT
12 PROGRAM TO CHECK GIVEN NUMBER IS PALINDROME
OR NOT

13 PROGRAM FOR SUM OF EVEN & ODD NUMBERS IN THE


GIVEN RANGE
14 PROGRAM TO CHECK THE BIGGEST OF TWO NUMBER
15 PROGRAM TO GENERATE CURRENT BILL FROM THE
TABLE
16 PROGRAM TO FIND THE TOTAL AND AVERAGE OF THE
STUDENT AND STORE THE DETAILS IN ANOTHER
TABLE
SHIPMENT DATABASE
DATABASE

SAILORS( Sailor_id, Sailor_name, Sailor _rating , Sailor_age)


BOATS ( Boat_id, Boat_name, Boat_color)
RESERVES(Sailor_id, Boat_id, Day)

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> desc sailors


Name Null? Type
----------------------------------------- -------- ----------------------------
SAILOR_ID NOT NULL NUMBER(2)
SAILOR_NAME CHAR(10)
SAILOR_RATING NUMBER(3)
SAILOR_AGE NUMBER(3)

SQL> desc boats


Name Null? Type
----------------------------------------- -------- ----------------------------
BOAT_ID NOT NULL NUMBER(3)
BOAT_NAME CHAR(10)
BOAT_COLOR CHAR(6)

SQL> desc reserves


Name Null? Type
----------------------------------------- -------- ----------------------------
SAILOR_ID NOT NULL NUMBER(2)
BOAT_ID NUMBER(3)
DAY CHAR(10)
INSERTING DATA INTO THE DATABASE:

SQL> insert into sailors values('&sailor_id','&sailor_name','&sailor_rating','&sailor_age');


Enter value for sailor_id: 1
Enter value for sailor_name: raju
Enter value for sailor_rating: 45
Enter value for sailor_age: 26
old 1: insert into sailors values('&sailor_id','&sailor_name','&sailor_rating','&sailor_age')
new 1: insert into sailors values('1','raju','45','26')
1 row created.

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> insert into boats values('&boat_id',' &boat_name','&boat_color');


Enter value for boat_id: 11
Enter value for boat_name: queen
Enter value for boat_color: red
old 1: insert into boats values('&boat_id',' &boat_name','&boat_color');
new 1: insert into boats values('11’,' queen','red');
1 row created.

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> insert into reserves values('&sailor_id', '&boat_id','&day');


Enter value for sailor_id: 1
Enter value for boat_id: 11
Enter value for day: sunday
old 1: insert into reserves values('&sailor_id', '&boat_id','&day')
new 1: insert into reserves values('1', '11','sunday')
1 row created.

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;

SAILOR_ID BOAT_ID DAY


---------- ---------- ----------
1 11 sunday
2 12 monday
3 13 Tuesday

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

2) Find the name of sailors who have reserved a red boat


SQL> select s.sailor_name from sailors s, reserves r, boats b where s.sailor_id =
r.sailor_id and r. boat_id = b.boat_id and boat_color='red';
SAILOR_NAM
----------
Raju

3) Find the names of sailors with the highest rating


SQL> select s.sailor_name from sailors s where s.sailor_rating >= all(select
s1.sailor_rating from sailors s1)
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

5) Find the ages of sailors whose names begin with r


SQL> select s.sailor_age from sailors s where s.sailor_name like 'r%';
SAILOR_AGE
----------
26
32
UNIVERSITY DATABASE

STUDENT (snum ,sname,major,level,age)


CLASS (cname,meet,room,fid)
ENROLLED (snum,cname)
FACULTY (fid,fname,depfid)

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.

SQL>create table enrolled(snum number(10), cname char(10), primary


key(snum,cname));

Table created.

SQL>create table faculty(fid number(5) primary key, fname char(10), depfid


number(5));

Table created.
DEFINITION OF THE DATABASE:

SQL> desc student;

Name Null? Type


----------------------------------------- -------- ----------------------------
SNUM NOT NULL NUMBER(5)
SNAME CHAR(10)
MAJOR CHAR(10)
LEV CHAR(10)
AGE NUMBER(2)

SQL> desc class;

Name Null? Type


----------------------------------------- -------- ----------------------------
CNAME NOT NULL CHAR(10)
MEET NUMBER(3)
ROOM NUMBER(4)
FID NUMBER(5)

SQL> desc enrolled;

Name Null? Type


----------------------------------------- -------- ----------------------------
SNUM NOT NULL NUMBER(2)
CNAME NOT NULL CHAR(10)

SQL> desc faculty;

Name Null? Type


----------------------------------------- -------- ----------------------------
FID NOT NULL NUMBER(5)
FNAME CHAR(10)
DEPFID NUMBER(5)
INSERTING DATA INTO THE DATABASE:

SQL> insert into student values('&snum','&sname','&major','&lev','&age');


Enter value for snum: 101
Enter value for sname: krishna
Enter value for major: y
Enter value for lev: sr
Enter value for age: 26
old 1: insert into student values('&snum','&sname','&major','&lev','&age')
new 1: insert into student values('101','krishna','y','a','26')

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.

SQL> select * from student;

SNUM SNAME MAJOR LEV AGE


---------- ---------- ---------- ---------- ----------
101 krishna y sr 26
102 kumari n jr 17
103 lavanya y sr 20
104 laya y sr 20

SQL> insert into class values('&cname','&meet','&room','&fid');


Enter value for cname: bsc
Enter value for meet: 10
Enter value for room: 2
Enter value for fid: 201
old 1: insert into class values('&cname','&meet','&room','&fid')
new 1: insert into class values('bsc','10','2','201')

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> select * from class;

CNAME MEET ROOT FID


---------- ---------- ---------- ----------
bsc 10 2 201
bcom 9 7 203
ba 8 3 204

SQL> insert into enrolled values('&snum','&cname');


Enter value for snum: 101
Enter value for cname: bsc
old 1: insert into enrolled values('&snum','&cname')
new 1: insert into enrolled values('101','bsc')
1 row created.
SQL> /
Enter value for snum: 102
Enter value for cname: bsc
old 1: insert into enrolled values('&snum','&cname')
new 1: insert into enrolled values('102','bsc')
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.

SQL> select * from enrolled;

SNUM CNAME
---------- ----------
101 bsc
102 bsc
103 bcom

SQL> insert into faculty values('&fid','&fname','&depfid');


Enter value for fid: 201
Enter value for fname: ramana
Enter value for depfid: 1
old 1: insert into faculty values('&fid','&fname','&depfid')
new 1: insert into faculty values('201','ramana','1')

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.

SQL> select * from faculty;

FID FNAME DEPFID


---------- ---------- ----------
201 ramana 1
203 harsha 2
204 gayatri 3

QUERIES:

1) Print the level and the average age of students for that level for each level

SQL> select s.lev,avg(s.age) from student s group by s.lev

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

4) Find the names of faculty belong to department 1

SQL> select fname from faculty where depfid =1;

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.

DEFINITION OF THE DATABASE:

SQL> desc employee;


Name Null? Type
----------------------------------------- -------- ----------------------------
SSN NOT NULL NUMBER(4)
FNAME CHAR(10)
LNAME CHAR(10)
DOB DATE
AD VARCHAR2(10)
SAL NUMBER(5)
COMM NUMBER(5)
DNO NUMBER(5)

SQL> desc department;


Name Null? Type
----------------------------------------- -------- ----------------------------
DNO NOT NULL NUMBER(5)
DNAME CHAR(10)
LOC CHAR(5)

INSERTING DATA INTO THE DATABASE:

SQL> insert into department values('&dno','&dname','&loc');


Enter value for dno: 1
Enter value for dname: computers
Enter value for loc: mvp
old 1: insert into department values('&dno','&dname','&loc')
new 1: insert into department values('1','computers','mvp')

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.

SQL> select * from department;

DNO DNAME LOC


---------- ---------- -----
1 computers mvp
2 synergies kkd
3 diamond gwk

SQL> insert into employee values('&ssn','&fname','&lname','&dob','&ad','&sal','&comm','&dno');


Enter value for ssn: 11
Enter value for fname: krishna
Enter value for lname: kumari
Enter value for dob: 25-may-1990
Enter value for ad: mvp
Enter value for sal: 20000
Enter value for comm: 500
Enter value for dno: 1
old 1: insert into employee values('&ssn','&fname','&lname','&dob','&ad','&sal','&comm','&dno')
new 1: insert into employee values('11','krishna','kumari','25-may-1990','mvp','20000','500','1')

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.

SQL> select * from employee;


SSN FNAME LNAME DOB AD SAL COMM DNO

---------- ---------- ---------- --------- ---------- ---------- ---------- ---------


11 krishna kumari 25-MAY-90 mvp 20000 500 1

12 swathi lanka 24-JUN-91 gwk 10000 2

13 ranga kanti 27-APR-94 mvp 20000 400 3

QUERIES:

1) Update the comm is 1000 having salary greater than 20000

SQL>update employee set comm =1000 where sal>20000;

2 rows updated

SQL>select * from employee;

SSN FNAME LNAME DOB AD SAL COMM DNO

---------- ---------- ---------- --------- ---------- ---------- ---------- ---------


11 krishna kumari 25-MAY-90 mvp 20000 1000 1
13 ranga kanti 27-APR-94 mvp 20000 1000 3

2) Print the name and address of all employees who work for the department computers

SQL>Select e.fname,e.ad from employee e, department d where e.dno = d.dno and


d.dname =’computers’

FNAME AD
---------- ----------
Krishna mvp
Ranga mvp

3) Print the employee details whose comm is null


SQL > select * from employee where comm is null;

SSN FNAME LNAME DOB AD SAL COMM DNO

---------- ---------- ---------- --------- ---------- ---------- ---------- ---------


12 swathi lanka 24-JUN-91 gwk 10000 2

4) Print the employee details who got highest salary

SQL> select * from emp where sal = ( select max(sal) from employee)

SSN FNAME LNAME DOB AD SAL COMM DNO

---------- ---------- ---------- --------- ---------- ---------- ---------- ---------


11 krishna kumari 25-MAY-90 mvp 20000 1000 1
13 ranga kanti 27-APR-94 mvp 20000 1000 3

5) Print the ssn and total salary (comm+sal)

SQL> select ssn, sum(sal+comm) from employee group by ssn;

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

7) Delete the record of the employee whose number is 11


SQL> delete from employee wwhere ssn =11;

1 row deleted

SQL> select * from employee;

SSN FNAME LNAME DOB AD SAL COMM DNO

---------- ---------- ---------- --------- ---------- ---------- ---------- ---------


12 swathi lanka 24-JUN-91 gwk 10000 2

13 ranga kanti 27-APR-94 mvp 20000 1000 3

8) Print the details of the employee whose name start with the letter ‘s’

SQL> select * from employee where fname is like ‘s%’;

SSN FNAME LNAME DOB AD SAL COMM DNO

---------- ---------- ---------- --------- ---------- ---------- ---------- ---------


12 swathi lanka 24-JUN-91 gwk 10000 2

9) Write a query to add new field phone number into the table employee

SQL> alter table employee add( ph number(10));

Table altered.

SQL> desc employee;

Name Null? Type


---------------------------------------- -------- ----------------------------
SSN NOT NULL NUMBER(4)
FNAME CHAR(10)
LNAME CHAR(10)
DOB DATE
AD VARCHAR2(10)
SAL NUMBER(5)
COMM NUMBER(5)
DNO NUMBER(5)
PH NUMBER(10)

10) Print the name of the employee whose date of birth 27-apr-94
SQL> select * from employee where dob =’27-apr-1994’;

SSN FNAME LNAME DOB AD SAL COMM DNO

---------- ---------- ---------- --------- ---------- ---------- ---------- ---------

13 ranga kanti 27-APR-94 mvp 20000 1000 3


PROGRAM TO PRINT THE MULTIPLICATION TABLE

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> /

Enter value for n: 2


old 6: n := &n;
new 6: n := 2;

The Multiplication table for 2

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

PL/SQL procedure successfully completed.


PROGRAM TO PRINT THE FIBONACCI SERIES

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> /

Enter value for n: 10


old 8: n := &n;
new 8: n := 10;

The fibonacci series is


0
1
1
2
3
5
8
13
21
34

PL/SQL procedure successfully completed.


PROGRAM TO PRINT THE EMPLOYEE DETAILS FROM THE EMP TABLE

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

PL/SQL procedure successfully completed.


PROGRAM TO UPDATE THE SALARY OF THE GIVEN EMPLOYEE

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;

PL/SQL procedure successfully completed.

SQL>select * from emp where empno=7369;

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO


------ ---------- --------- ---------- --------- ---------- ---------- ------
7369 SMITH CLERK 7902 17-DEC-80 800 20

SQL>select * from emp where empno=7369;

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO


------ ---------- --------- ---------- --------- ---------- ---------- ------
7369 SMITH CLERK 7902 17-DEC-80 1600 20
PRINT HRA ,DA ,INSURANCE,INCOMETAX,GROSS SALARY OF THE GIVEN
EMPLOYEE NUMBER

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

PL/SQL procedure successfully completed.


PROGRAM TO PRINT THE NATURAL NUMBERS AND ITS SUM

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

PL/SQL procedure successfully completed.


PROGRAM TO SWAP THE NUMBERS WITH OUT USING THIRD VARIABLE

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

PL/SQL procedure successfully completed.


PROGRAM TO FIND THE GIVEN NUMBER IS STRONG NUMBER OR NOT

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

PL/SQL procedure successfully completed.

SQL> /
Enter value for n: 5
old 8: n:= &n;
new 8: n:= 5;
The given number is not a strong number

PL/SQL procedure successfully completed.


PROGRAM TO CHECK GIVEN NUMBER IS PALINDROME OR NOT

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

PL/SQL procedure successfully completed.

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

PL/SQL procedure successfully completed.


PROGRAM FOR SUM OF EVEN & ODD NUMBERS IN THE GIVEN RANGE

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

PL/SQL procedure successfully completed.


PROGRAM TO CHECK THE BIGGEST OF TWO NUMBERS

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

PL/SQL procedure successfully completed.


PROGRAM TO GENERATE CURRENT BILL FROM THE TABLE

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> SELECT * FROM E;

MNO CNAME CUR_READ PREV_READ


---------- ---------- ---------- ----------
1 krishna 3456 1234
2 santoshi 7890 6785

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

PL/SQL procedure successfully completed.


PROGRAM TO FIND THE TOTAL AND AVERAGE OF THE STUDENT AND STORE THE
DETAILS IN ANOTHER TABLE

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:

SQL> select * from std;

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;

PL/SQL procedure successfully completed.

SQL> select * from abstract;

STDNO STDNAME CLAS TOT AVG G


---------- ---------- ---- ---------- ---------- -
1 lavanya bsc 224 75 A
INDEX

S.No. Name of the practical Page.No.

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

You might also like